- https://indepth.dev/everything-you-need-to-know-about-the-expressionchangedafterithasbeencheckederror-error/ (***) (clear descriptions)
- https://stackoverflow.com/questions/34364880/expression-has-changed-after-it-was-checked (**)
A running Angular application is a tree of components. During change detection Angular performs checks for each component which consists of the following operations performed in the specified order:
- update bound properties for all child components/directives
- call
ngOnInit,OnChangesandngDoChecklifecycle hooks on all child components/directives - update DOM for the current component
- run change detection for a child component
- call
ngAfterViewInitlifecycle hook for all child components/directives
fddf
Possible fixes of ExpressionChangedAfterItHasBeenCheckedError:
Asynchronous update: use setTimeout
setTimeout(() => {
this.parent.name = 'updated name';
});
Forcing change detection: use the changeDetection
constructor(private cd: ChangeDetectorRef) {
}
ngAfterViewInit() {
this.cd.detectChanges();
}
No comments:
Post a Comment