Lets Have a fun with Technology.

BTemplates.com

Follow by Email

Thursday, July 6, 2017

Angular 2 trigger change detection.


There are three way to implement change detection in Angular 2.

1. ChangeDetectorRef.detectChanges() 

   This is most common used.
   This will Checks only in component and its children.
   Details of class can be read at
   https://angular.io/api/core/ChangeDetectorRef#!#detectChanges-anchor

2. ApplicationRef.tick()

   It will check for full component tree.
   Details of class can be read at
   https://angular.io/api/core/ApplicationRef#!#tick-anchor

3. NgZone.run(callback)

   It will check the full component tree after executing the callback function.
   Details of class can be read at
   https://angular.io/api/core/NgZone#!#run-anchor

You can choose one method from above.

inject ApplicationRef, NgZone, or ChangeDetectorRef into your component

Hope this will be help full.

0 comments:

Post a Comment