Runtime error: unable to resume activity. TypeError :this.callResume is not a function in nativescript angular2
Runtime error: unable to resume activity. TypeError :this.callResume is not a function in nativescript angular2
在resume Event我不得不调用这个方法this.callResume()
。当我调用该方法时出现运行时错误:
TypeError :this.callResume is not a function
我不知道如何从 lifecycle.I 中的 resume 方法中调用方法,在构造函数中放置了 resume 方法。
constructor() {
applicationOn(resumeEvent, function (args: ApplicationEventData) {
if (args.android) {
// For Android applications, args.android is an android activity class.
console.log("Activity: " + args.android);
this.callResume();
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log("UIApplication: " + args.ios);
}
});
}
callResume():void{
console.log("ResumeCalled", "Test");
}
使用箭头函数符号 ()=>
而不是 function
。将您的代码更改为以下内容:
constructor() {
applicationOn(resumeEvent, (args: ApplicationEventData) => {
if (args.android) {
// For Android applications, args.android is an android activity class.
console.log("Activity: " + args.android);
this.callResume();
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log("UIApplication: " + args.ios);
}
});
}
在resume Event我不得不调用这个方法this.callResume()
。当我调用该方法时出现运行时错误:
TypeError :this.callResume is not a function
我不知道如何从 lifecycle.I 中的 resume 方法中调用方法,在构造函数中放置了 resume 方法。
constructor() {
applicationOn(resumeEvent, function (args: ApplicationEventData) {
if (args.android) {
// For Android applications, args.android is an android activity class.
console.log("Activity: " + args.android);
this.callResume();
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log("UIApplication: " + args.ios);
}
});
}
callResume():void{
console.log("ResumeCalled", "Test");
}
使用箭头函数符号 ()=>
而不是 function
。将您的代码更改为以下内容:
constructor() {
applicationOn(resumeEvent, (args: ApplicationEventData) => {
if (args.android) {
// For Android applications, args.android is an android activity class.
console.log("Activity: " + args.android);
this.callResume();
} else if (args.ios) {
// For iOS applications, args.ios is UIApplication.
console.log("UIApplication: " + args.ios);
}
});
}