I'm using Angular2 build 2.0.0-alpha.34 and I'm not sure why these two different pieces of code are giving me different results.
The only difference is using @Inject(TitleService) titleService vs using titleService: TitleService
This correctly works (ES2015 way)
import {Inject, Component, View, bootstrap, NgFor} from 'angular2/angular2';
import {titleComponent} from './components/title';
import {TitleService} from './services/services';
// Annotation section
@Component({
selector: 'my-app'
})
@View({
templateUrl: './html/app.html',
directives: [titleComponent, NgFor]
})
// Component controller
class MyAppComponent {
titles: Array<Object>;
constructor(@Inject(TitleService) titleService) {
console.log(titleService)
this.titles = titleService.getTitles();
}
}
bootstrap(MyAppComponent,[TitleService]);
This doesn't work (TypeScript way), it doesn't ever make it to the console.log call in constructor, but it doesn't throw an error
import {Inject, Component, View, bootstrap, NgFor} from 'angular2/angular2';
import {titleComponent} from './components/title';
import {TitleService} from './services/services';
// Annotation section
@Component({
selector: 'my-app'
})
@View({
templateUrl: './html/app.html',
directives: [titleComponent, NgFor]
})
// Component controller
class MyAppComponent {
titles: Array<Object>;
constructor(titleService: TitleService) {
console.log(titleService)
this.titles = titleService.getTitles();
}
}
bootstrap(MyAppComponent,[TitleService]);
If I'm using TypeScript's way to inject, do I need to do something else somewhere?