My situation involves passing information to two children components.
parent.component.html
<childA [loading]="loading">
<childB (loadingChanged)="loadingChangedHandler($event)"></childB>
</childA>
parent.component.ts
loading = false;
constructor(){
......
}
loadingChangedHandler(loadingChild: boolean){
this.loading = loadingChild;
}
childB.component.ts (sending a variable to parent, which then goes to child A)
....
@Output() loadingChanged: EventEmitter<boolean> = new EventEmitter();
....
loadData() {
this.loadingChanged.emit(true);
this.service.readDate()
.subscribe((data: any) => {
........
this.loadingChanged.emit(false);
})
}
Lastly, in the childA component, I need to receive the variable and perform operations
childA.component.ts
@Input() loading: boolean = false
constructor() {
....}
....
In child A, I have a loading spinner that works fine, but I am encountering an error in the console:
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'loading: false'. Current value: 'loading: true'.
How can I resolve this issue? I have looked into documentation (ngAfterViewInit) but I am struggling to understand why it's not working in my case.