Angular 2 - 是否有事件,当 UI 绑定完成时

Mar*_*erl 2 angular

如果我在组件中更改有界对象的值,an​​gular 会自动更新 UI 上的值。此更新过程需要几毫秒(取决于设备)。UI更新过程完成时是否有事件?

目前我使用以下代码:

// refresh binding
boundedItem = newValue;

// wait 100 milliseconds and the open the browsers print view 
setTimeout(() => {
    // open browser print view
}, 100);
Run Code Online (Sandbox Code Playgroud)

在慢速设备(智能手机)上,该过程可能需要 100 多毫秒,因此代码并不是很干净。

Gün*_*uer 6

只需显式调用更改检测,然后您就知道在执行进一步代码之前更新了视图:

constructor(private cdRef:ChangeDetectorRef)  {}

someMethod() {
  boundedItem = newValue;
  this.cdRef.detectChanges();
  // view update is completed here
}
Run Code Online (Sandbox Code Playgroud)