Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (39 sloc) 1.25 KB
import {Component,Input, ChangeDetectionStrategy, Output, EventEmitter, AfterViewChecked} from "angular2/core";
import {TodoItem} from "./todo_item";
import {Todo} from "./todo";
selector: 'todo-list',
// uncomment to switch to on-push mode
//changeDetection: ChangeDetectionStrategy.OnPush,
directives: [TodoItem],
template: `<ul>
<li *ngFor="#todo of todos;">
<todo-item [todo]="todo" (toggle)="onToggle($event)"></todo-item>
<button (click)="blowup()">Trigger Change Detection Loop</button>`
export class TodoList implements AfterViewChecked {
todos: Array<Todo>;
callback: Function;
addTodo = new EventEmitter<Object>();
clicked = false;
onToggle(todo) {
console.log("toggling todo..");
todo.completed = !todo.completed;
blowup() {
console.log("Trying to blow up change detection...");
this.clicked = true;
ngAfterViewChecked() {
if (this.callback && this.clicked) {
console.log("changing status ...");
You can’t perform that action at this time.