I've got a service that has an array of selected ID's. When I init a component I perform a check for presence of that component's ID in the array. However, Angular throws an exception that value has been changed after view check.
I've tried to add detectChanges()
right after this._checked = true
, tried markForCheck()
. Also, I've tried to move both cases to different life cycle hooks with no success except for that it started working although throwing an error.
Angular change detection is like meat grinder and you are trying to alter the meat in the process. Typically, markForCheck()
should be enough in this case. If you post your full code we can try to figure out why it's not working in your situation. If all fails, you can always do:
setTimeout(() => {
this.youChanges();
this.changeDetectorRef.markForCheck();
});