Sharing Top Content from the Angular-sphere.

Injecting services in services in Angular 2

  • TypeScript only generates metadata for a class, method, property or method/constructor parameter when a decorator is actually attached to that particular code.
  • import { Inject } from ‘@angular/core’ ; import { Http } from ‘@angular/http’ ; class DataService { items : Array < any > ; constructor ( @ Inject ( Http ) http : Http ) { …
  • Inject ( Http )), __metadata ( ‘design:paramtypes’ , [ Http ]) ], DataService );
  • We could remove @Inject again and use something else that we put on the class, because that will cause TypeScript to emit metadata for the constructor parameters too.
  • We need providers for the injector, so it knows about Http .

Read the full article, click here.

@PascalPrecht: “Understanding @Injectable() in Angular 2”

When writing Angular 2 applications, it often happens that we build services that depend on other service instances. In our previous articles, we learned about the Dependency Injection system in Angular 2 and how it works. However, it turns out that we might run into unexpected behaviour when injecting service dependencies. This article details how to do it right.

Injecting services in services in Angular 2

Comments are closed, but trackbacks and pingbacks are open.