Each of the angular component uses Default change detection policy by default. UI keep checking for the change continuously. Which many times affect the performance of the component and overall product.
There is a way you can control this by setting the Change Detection for your component.
How to find out the effect Change detection is putting on your control.
Override ngAfterViewChanged event on your component and use code similar to below.
Inject "private _ngZone : NgZone" to your constructor.
divElement is the Element in your html.
and highlight-css , change the background color of the div with css.
You will see how many times the event fires.
Changing the Default Change Detection:
- You can change the default change detection by setting the changeDetection to OnPush in your Component declaration.
Ref:
https://medium.com/ngconf/simplified-angular-change-detection-e74809ff804d
https://pankajparkar.github.io/demystifying-change-detection/#/default-strategy