Last active
July 21, 2017 00:08
-
-
Save amikitevich/9bd22d3a0bf88f1d9833e1611752ce86 to your computer and use it in GitHub Desktop.
Revisions
-
amikitevich revised this gist
Jul 21, 2017 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,6 +30,7 @@ export class TodoService { @Component({ selector: 'todo-list', template: `<todo-item *ngFor="let item of items$ | async" [todo]="item"></todo-item>`, changeDetection: ChangeDetectionStrategy.OnPush }) export class TodoListComponent implements OnInit { @@ -46,6 +47,7 @@ export class TodoListComponent implements OnInit { @Component({ selector: 'todo-item', template: `Category: {{categoryName$ | async}}: {{todoText$ | async}}`, changeDetection: ChangeDetectionStrategy.OnPush }) export class TodoItemComponent implements OnInit { @@ -67,3 +69,5 @@ export class TodoItemComponent implements OnInit { } } } -
amikitevich revised this gist
Jul 20, 2017 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,11 +31,15 @@ export class TodoService { selector: 'todo-list', template: `<todo-item *ngFor="let item of items$ | async" [todo]="item"></todo-item>`, }) export class TodoListComponent implements OnInit { public items$: Observable<Todo[]>; constructor(private todoService: TodoService) { } ngOnInit() { this.items$: Observable<Todo[]> = this.todoService.getTodoItems(); } } -
amikitevich created this gist
Jul 20, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ /** * service that emulates http */ @Injectable() export class TodoService { readonly todos = [ {id: 1, text: 'todo1', categoryId: 1}, {id: 2, text: 'todo2', categoryId: 2}, {id: 3, text: 'todo3', categoryId: 1}, {id: 4, text: 'todo4', categoryId: 1} ]; readonly todoCategory = [ {id: 1, name: 'todoCategory1'}, {id: 2, name: 'todoCategory1'} ]; public getTodoItems() { return Observable.of(this.todos); } public getCategory(categoryId: number) { const category = this.todoCategory.find(item => item.id === categoryId); return Observable.of(category); } } @Component({ selector: 'todo-list', template: `<todo-item *ngFor="let item of items$ | async" [todo]="item"></todo-item>`, }) export class TodoListComponent { public items$: Observable<Todo[]> = this.todoService.getTodoItems(); constructor(private todoService: TodoService) { } } @Component({ selector: 'todo-item', template: `Category: {{categoryName$ | async}}: {{todoText$ | async}}`, }) export class TodoItemComponent implements OnInit { readonly todo$ = new ReplaySubject<Todo>(1); public todoCategoryName$: Observable<TodoCategory>; @Input() set todo(value: Todo) { this.todo$.next(value); } constructor(private todoService: TodoService) { } ngOnInit() { this.todoCategoryName$ = this.todo$ .switchMap(todo => this.todoService.getCategory(todo.categoryId)) .pluck('name'); } }