在constructor中导入ChangeDetectorRef组件,通过手动控制检查机制的开始和结束
import { Component, ChangeDetectorRef } from 'angular2/core'
@Component({
selector: 'my-app',
template: `<div>I'm {{message}} </div>`,
})
export class App {
message: string = 'loading :(';
constructor(cdr: ChangeDetectorRef) {
this.cdr = cdr;
}
ngAfterViewInit() {
this.cdr.detach(); // 停止检测
let componentRef = viewContainerRef.createComponent(componentFactory);
(<ModalBodyComponent>componentRef.instance).data = this.config.data;
setTimeout(() => this.cdr.reattach()); // 待组件动态加载完之后重新 attach
}}