Created
June 6, 2019 23:01
-
-
Save arturovt/2347d6a3d4b72fb00a7d6ecc2c20479d to your computer and use it in GitHub Desktop.
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 characters
import { Component, ChangeDetectionStrategy } from '@angular/core'; | |
@Component({ | |
selector: 'app-todos', | |
template: ` | |
<button (click)="loadTodos()">Load todos</button> | |
<app-todo *ngFor="let todo of todos" [todo]="todo"></app-todo> | |
`, | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class TodosComponent { | |
public todos: Todo[] = []; | |
constructor(private todoService: TodoService) {} | |
public loadTodos(): void { | |
this.todoService.getTodos().subscribe((todos) => { | |
this.todos = todos; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment