我在这个问题上看到了类似的问题,但没有答案对我有用.我有一个布尔值,只要异步任务完成就会改变,但奇怪的是,ngonchages不会随时更改.以下是我的代码:
import {
Component,
OnChanges,
SimpleChange
} from '@angular/core';
export class HomePage implements OnChanges {
isLoaded: boolean;
constructor() {
this.isLoaded = false;
this.loadData();
}
loadData() {
setTimeout(() => {
this.isLoaded = true;
console.log(this.isLoaded);
}, 3000);
}
ngOnChanges(changes) {
console.log("There has been a change ", changes); //this is not firing
}
}
Run Code Online (Sandbox Code Playgroud)