I am using Angular2
2.0.0-alpha.32 and not having any luck injecting a service. I am simply following along in the Step by Step Guide:
but the example they show does not seem to work for me. Worked fine until I attempted to refactor the hard-coded names from the MyListComponent ctor into a FriendsService service. Now, nothing shows up, and the constructor of both the FriendsService and MyListComponent never even get called. I saw somewhere where appInjector was going away, but I tried that and componentServices, viewInjector and hostInjector. Nothing worked for me. Should be something simple, but not getting any love. Can someone help me?
/// <reference path="typings/angular2/angular2.d.ts" />
import {Component, View, bootstrap, NgFor} from 'angular2/angular2';
class FriendsService
{
names: Array<string>;
constructor()
{
this.names = ["Amit", "Dusan", "Kristin", "Mike"];
}
}
@Component({
selector: 'my-list',
appInjector: [FriendsService]
})
@View({
templateUrl: 'ShowList.html',
directives: [NgFor]
})
class MyListComponent
{
name: string;
names: Array<string>;
constructor(friendsService:FriendsService)
{
this.name = "Pete";
this.names = friendsService.names;
}
}
bootstrap(MyListComponent, [FriendsService]);