Update
I highly recommend starting with the OP's self response first: properly think about what can be done in the constructor
vs what should be done in ngOnChanges()
.
Original
This is more a side note than an answer, but it might help someone. I stumbled upon this problem when trying to make the presence of a button depend on the state of the form:
<button *ngIf="form.pristine">Yo</button>
As far as I know, this syntax leads to the button being added and removed from the DOM based on the condition. Which in turn leads to the ExpressionChangedAfterItHasBeenCheckedError
.
The fix in my case (although I don't claim to grasp the full implications of the difference), was to use display: none
instead:
<button [style.display]="form.pristine ? 'inline' : 'none'">Yo</button>