Tuesday, May 23, 2017

Force a refresh with a zone?

Assuming zone: NgZone at component's constructor (in TypeScript in Angular 2), this can be a hacky way to force a component to refresh if the watchers aren't doing their job for some reason.

this.zone.run(() => {
   console.log('whatever');
});

 
 

Addendum 5/24/2017: public zone: NgZone or private zone: NgZone would be needed at the constructor to make this work somewhere beyond the constructor. Also note NgZone is kept in '@angular/core'

No comments:

Post a Comment