我们如何在应用程序事件中更新组件数据? this.matches = x被忽略
import * as app from "tns-core-modules/application";
export class HomeComponent implements OnInit {
matches; // How to refresh this??
constructor() {
app.on(app.resumeEvent, (args: app.ApplicationEventData) => {
// how to change matches here??
});
}
}
答案 0 :(得分:2)
您必须在NgZone中运行代码,因为恢复事件将在Angular的上下文之外触发。
constructor(ngZone: NgZone) {
app.on(app.resumeEvent, (args: app.ApplicationEventData) => {
ngZone.run(() => {
// Update here
});
});
}