如何从nativescript中的应用程序事件调用组件方法

如何从nativescript中的应用程序事件调用组件方法,nativescript,angular2-nativescript,Nativescript,Angular2 Nativescript,我们如何在应用程序事件中更新组件数据?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.Applicati

我们如何在应用程序事件中更新组件数据?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??
        });
    }
}

您必须在NgZone内运行代码,因为resume事件将在Angular的上下文之外触发

constructor(ngZone: NgZone) {
    app.on(app.resumeEvent, (args: app.ApplicationEventData) => {
         ngZone.run(() => {
            // Update here
         });
    });
}

你的问题不是很清楚吗?您希望在resumeEvent中更新什么?如何获得匹配的初始值?您可以在resumeEvent中使用相同的方法