Why is the component in this simple plunk
@Component({
selector: \'my-app\',
template: `I\'m {{message}} `,
})
export class App {
I couldnt comment on @Biranchi s post since I dont have enough reputation, but it fixed the problem for me.
One thing to note! If adding changeDetection: ChangeDetectionStrategy.OnPush on the component didn't work, and its a child component (dumb component) try adding it to the parent also.
This fixed the bug, but I wonder what are the side effects of this.
I got similar error while working with datatable. What happens is when you use *ngFor inside another *ngFor datatable throw this error as it interepts angular change cycle. SO instead of using datatable inside datatable use one regular table or replace mf.data with the array name. This works fine.
I switched from AfterViewInit to AfterContentChecked and It worked for me.
Here is the process
Add dependency in your constructor:
constructor (private cdr: ChangeDetectorRef) {}
and call your login in implemented method code here:
ngAfterContentChecked() {
this.cdr.detectChanges();
// call or add here your code
}
I fixed this by adding ChangeDetectionStrategy from angular core.
import { Component, ChangeDetectionStrategy } from '@angular/core';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'page1',
templateUrl: 'page1.html',
})
ngAfterViewChecked()
worked for me:
import { Component, ChangeDetectorRef } from '@angular/core'; //import ChangeDetectorRef
constructor(private cdr: ChangeDetectorRef) { }
ngAfterViewChecked(){
//your code to update the model
this.cdr.detectChanges();
}
For this I have tried above answers many does not work in latest version of Angular (6 or later)
I am using Material control that required changes after first binding done.
export class AbcClass implements OnInit, AfterContentChecked{
constructor(private ref: ChangeDetectorRef) {}
ngOnInit(){
// your tasks
}
ngAfterContentChecked() {
this.ref.detectChanges();
}
}
Adding my answer so, this helps some solve specific issue.