I have a general Angular question:
Why does Angular async
pipe use cdr.markForCheck()
instead of cdr.detectChanges()
?
What I see there are two main differences in these two 'styles':
markForCheck()
marks the path to be checked up to the root component - what to updatemarkForCheck()
lets the change detection happen in current or next cycle - timing
My thoughts or questions:
why do we need to check whole path to the root (in
async
pipe)? Why not just current component? (detectChanges()
) - this relates to what to updatewhy just mark only (for current/next cycle - in
markForCheck()
using ngZone)? Why not detect changes immedially? (detectChanges()
) this relates to timingwhat if there is no ngZone async trigger / no async operation? Then the view update won't happen?
what would happen if we changed
async
pipe to usedetectChanges()
instead?
private _updateLatestValue(async: any, value: Object): void {
if (async === this._obj) {
this._latestValue = value;
this._ref.markForCheck();
}
}
Edit:
Please do not explain what each of the methods does as I read it in docs many times and it is not comprehensible for me to understant from the async
point of view.
The important part for me to know is why in regards to what to update and timing.