// #docregion import { Component } from '@angular/core'; import { Todo } from './todo'; import { TodoListComponent } from './todo_list'; import { TodoFormComponent } from './todo_form'; @Component({ selector: 'todo-app', template: `

Todo

{{remaining}} of {{todos.length}} remaining [ archive ] `, styles: ['a { cursor: pointer; cursor: hand; }'], directives: [TodoListComponent, TodoFormComponent] }) export class TodoAppComponent { todos: Todo[] = [ {text: 'learn angular', done: true}, {text: 'build an angular app', done: false} ]; get remaining() { return this.todos.filter(todo => !todo.done).length; } archive(): void { let oldTodos = this.todos; this.todos = []; oldTodos.forEach(todo => { if (!todo.done) { this.todos.push(todo); } }); } addTask(task: Todo) { this.todos.push(task); } }