When tracking a change of variable and wanting to run a function after the change, I utilized the ngAfterViewChecked hook. However, since this method involves data submission which should only occur once, I incorporated a boolean status variable to manage it like so:
ngAfterViewChecked()
{
//status is a boolean variable which is true
if (this.status)
{
this.status=!this.status;
this.myFunction();
}
}
myFunction
{
//some code
}
Although, I noticed multiple data submissions and encountered the following error:
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value for '@dialogContainer': 'enter'. Current value: 'exit'.
I suspect that NgAfterViewChecked is triggered for every change, leading to the issue where if (this.status){} might be executed before the status changes to false.
Is there a solution to resolve this problem?