In my Angular app ngDoCheck
, ngAfterViewChecked
always executed twice while startup.
this answer tell me that Angular calls twice the change detection after the first one, in development mode.
I have run this command to enter production mode.
ng serve --environment=prod --target=production
and, Angular still called the hook twice.
Updated:
As yurzui said in the comment, Angular run Change Detection twice in dev mode: detectChanges
and checkNoChanges
(yurzui: i also said that angular calls app.tick()(that includes detectChanges and checkNoChanes(dev)) method twice on first start). The former to propagate changes, and the latter to make sure there are no changes. (see: Two Phases of Angular Applications)
But i don't understand why Angular calls detectChanges
and checkNoChanges
twice, at startup. So Change Detection called 4 times. Aren't 2 just enough?