ExpressionChangedAfterItHasBeenCheckedError Explained

前端 未结 26 1998
慢半拍i
慢半拍i 2020-11-22 14:46

Please explain to me why I keep getting this error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.

Obviously,

26条回答
  •  感动是毒
    2020-11-22 15:26

    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:

    
    

    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:

    
    

提交回复
热议问题