Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Dynamic change in label of mat-option gives ExpressionChangedAfterItHasBeenCheckedError #14793
What is the expected behavior?
Error should not occur for this scenario.
What is the current behavior?
Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'null: '. Current value: 'null: Change to localized version'.
What are the steps to reproduce?
Essentially I mimicked a similar thing that I am seeing with this stackblitz.
Our form field select is like so:
What happens is those labels start off as null and when the service comes back with the proper string it changes it and this is where the expressed changed error comes into play. So my stackblitz simulates this with having option1 as a variable in OnInit I put a setTimeout for 2 seconds to change the string and there error comes up.
I guess I am wondering if this is truly a bug or if I need to do something different to not allow this to happen. I did get this to work by manually calling a change detection after the localize variable we have gets populated (and take the pipe out of the equation) but this is a workaround to the problem I feel like.