3

If I change the value of a bounded object in my component, angular automatically updates the value on the UI. This update-process takes some milliseconds (depend on the device). Is there an event when the UI-update-process finished?

At the moment I use following code:

// refresh binding
boundedItem = newValue;

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

On slow devices (smartphones) the process could be take more than 100 milliseconds, so the code is not really clean.

Martin Schagerl
  • 583
  • 1
  • 7
  • 19

2 Answers2

7

Just invoke change detection explicitely, then you know the view is updated before further code is executed:

constructor(private cdRef:ChangeDetectorRef)  {}

someMethod() {
  boundedItem = newValue;
  this.cdRef.detectChanges();
  // view update is completed here
}
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

You can try this Life-cycle hook:

ngAfterViewInit(){

}
Rohit Rane
  • 2,790
  • 6
  • 25
  • 41