ExpressionChangedAfterItHasBeenCheckedError Explained

前端 未结 26 1523
慢半拍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:49

    I was facing the same problem as value was changing in one of the array in my component. But instead of detecting the changes on value change, I changed the component change detection strategy to onPush (which will detect changes on object change and not on value change).

    import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
    
    @Component({
        changeDetection: ChangeDetectionStrategy.OnPush
        selector: -
        ......
    })
    
    0 讨论(0)
  • 2020-11-22 15:52

    For my issue, I was reading github - "ExpressionChangedAfterItHasBeenCheckedError when changing a component 'non model' value in afterViewInit" and decided to add the ngModel

    <input type="hidden" ngModel #clientName />
    

    It fixed my issue, I hope it helps someone.

    0 讨论(0)
提交回复
热议问题