77 */
88
99import { CommonModule , NgForOf , NgIf } from '@angular/common' ;
10- import { ChangeDetectionStrategy , Component , EventEmitter , InjectFlags , Injectable , Input , IterableDiffers , NgModule , Output , createInjector , defineInjector , inject , ɵComponentDef as ComponentDef , ɵComponentType as ComponentType , ɵDirectiveDef as DirectiveDef , ɵDirectiveType as DirectiveType , ɵNgOnChangesFeature as NgOnChangesFeature , ɵdefaultIterableDiffers as defaultIterableDiffers , ɵdefineDirective as defineDirective , ɵinjectTemplateRef as injectTemplateRef , ɵinjectViewContainerRef as injectViewContainerRef , ɵmarkDirty as markDirty , ɵrenderComponent as renderComponent } from '@angular/core' ;
10+ import { ChangeDetectionStrategy , Component , EventEmitter , InjectFlags , Injectable , Input , IterableDiffers , NgModule , Output , createInjector , defineInjector , inject , ɵComponentDef as ComponentDef , ɵComponentType as ComponentType , ɵDirectiveDef as DirectiveDef , ɵDirectiveType as DirectiveType , ɵNgOnChangesFeature as NgOnChangesFeature , ɵdefaultIterableDiffers as defaultIterableDiffers , ɵdefineDirective as defineDirective , ɵdirectiveInject as directiveInject , ɵinjectTemplateRef as injectTemplateRef , ɵinjectViewContainerRef as injectViewContainerRef , ɵmarkDirty as markDirty , ɵrenderComponent as renderComponent } from '@angular/core' ;
1111
1212
1313export class Todo {
@@ -23,7 +23,7 @@ export class Todo {
2323 }
2424}
2525
26- @Injectable ( )
26+ @Injectable ( { providedIn : 'root' } )
2727export class TodoStore {
2828 todos : Array < Todo > = [
2929 new Todo ( 'Demonstrate Components' ) ,
@@ -108,12 +108,9 @@ export class TodoStore {
108108 // changeDetection: ChangeDetectionStrategy.OnPush
109109} )
110110export class ToDoAppComponent {
111- todoStore : TodoStore ;
112111 newTodoText = '' ;
113112
114- // TODO(misko) Fix injection
115- // constructor(todoStore: TodoStore) { this.todoStore = todoStore; }
116- constructor ( ) { this . todoStore = new TodoStore ( ) ; }
113+ constructor ( public todoStore : TodoStore ) { }
117114
118115 stopEditing ( todo : Todo , editedTitle : string ) {
119116 todo . title = editedTitle ;
@@ -157,10 +154,7 @@ export class ToDoAppComponent {
157154 type : NgForOf ,
158155 selectors : [ [ '' , 'ngFor' , '' , 'ngForOf' , '' ] ] ,
159156 factory : ( ) => new NgForOf (
160- injectViewContainerRef ( ) , injectTemplateRef ( ) ,
161- // TODO(misko): inject does not work since it needs to be directiveInject
162- // inject(IterableDiffers, defaultIterableDiffers)
163- defaultIterableDiffers ) ,
157+ injectViewContainerRef ( ) , injectTemplateRef ( ) , directiveInject ( IterableDiffers ) ) ,
164158 features : [ NgOnChangesFeature ( {
165159 ngForOf : 'ngForOf' ,
166160 ngForTrackBy : 'ngForTrackBy' ,
0 commit comments