Skip to content

Instantly share code, notes, and snippets.

@arturovt
Created June 6, 2019 23:01
Show Gist options
  • Save arturovt/2347d6a3d4b72fb00a7d6ecc2c20479d to your computer and use it in GitHub Desktop.
Save arturovt/2347d6a3d4b72fb00a7d6ecc2c20479d to your computer and use it in GitHub Desktop.
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