I'm currently working with Angular2 build 2.0.0-alpha.34 and I can't figure out why I'm getting different results from these two code snippets.
The only variation is between using
@Inject(TitleService) titleService
and titleService: TitleService
This snippet works correctly (ES2015 method)
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 code doesn't function properly (TypeScript method), as it never reaches the console.log
statement in the constructor, but no error is thrown either
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 opt for TypeScript's injection method, is there something else I need to do elsewhere?