通常,您无需执行任何操作即可更新视图。zone.js将为您做一切。
但是,如果由于某种原因要手动触发更改检测(例如,如果代码在角度区域之外运行),则可以使用
LifeCycle::tick()method来执行。看到这个矮人
import {Component, LifeCycle, NgZone} from 'angular2/angular2'@Component({ selector: 'my-app', template: ` <div> Hello world!!! Time: {{ time }}. </div> `})export class App { time: number = 0; constructor(lc: LifeCycle, zone: NgZone) { zone.runOutsideAngular(() => { setInterval(() => { this.time = Date.now(); lc.tick(); // comment this line and "time" will stop updating }, 1000); }) } doCheck() { console.log('check', Date.now()); }}


