我在這個問題上看到過類似的問題,但沒有答案爲我工作。我有一個布爾值,每當一個異步任務完成時就會改變,但奇怪的是,任何時候ngonchages都不會觸發它的更改。下面是我的代碼:爲什麼ngOnchanges在angularjs中更改布爾值時不會觸發2
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
}
}
是'isLoaded'應該有上圖'bindings' /'@ input'屬性.. –