During my work with an angular component that uses
changeDetection: ChangeDetectionStrategy.OnPush
, I found myself utilizing the markForCheck
method. Initially, I placed it at the beginning of the function and saw positive results. However, upon reflection, I realized that it might be more effective to place it after all the function's actions are completed.
Interestingly, Angular was able to detect changes in both scenarios - whether the markForCheck
was called initially or after the actions were executed.
Now, I am curious about finding the optimal way to use markForCheck efficiently. Can someone provide insight into the best practice for utilizing markForCheck?
functionName() { // It works at both places
this.cd.markForCheck();
//
.... Some Code that needs markForCheck ....
//
this.cd.markForCheck();
}