ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'false'. Current value: 'true' 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: ExpressionChangedAfterItHasBeenCheckedError:

import { ChangeDetectorRef, AfterContentChecked} from '@angular/core';

  constructor(
  private cdref: ChangeDetectorRef) { }

  ngAfterContentChecked() {

    this.cdref.detectChanges();

  }

Example 3: 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