ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: code example

Example 1: angular ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.

constructor(private ref: ChangeDetectorRef){}

  ngAfterContentChecked() {
    this.ref.detectChanges();
  }

Example 2: expression changed after it has been checked

export class BComponent {
    @Input() text;

    constructor(private parent: AppComponent) {}

    ngOnInit() {
        this.parent.text = 'updated text';
    }
}<>Copy

Tags:

Misc Example