Injecting services in angular 2
Angular 2 applications can basically be written in any language, as long as it compiles to JavaScript in some way. When writing our application in TypeScript, we use decorators to add metadata to our code. Sometimes, we can even omit some decorators and simply rely on type annotations. However, it turns out that, when it comes to DI, we might run into unexpected behaviour when injecting dependencies into services. This article discusses what this unexpected problem is, why it exists and how it can be solved. Injecting Service Dependencies Let’s say we have a simple Angular 2 component which has a DataService dependency. It could look something like this: @ Component ({ selector : 'my-app' , template : ` < ul > < li * ngFor = "let item of items" > {{ item . name }} < /li > < /ul > ` }) class AppComponent { items : Array < any > ; constructor ( dataService : DataService ) { this...