我想从离子警报对话框的处理程序中调用directUpdateContext.start()函数。为此,我将上下文从directUpdate.js文件传递到了呈现警报的appcomponent.ts文件,但是directUpdateData和directUpdateContext作为未定义传递。
wldirectupdate.js文件。
var objectData;
var objectContext;
function wlCommonInit() {
console.log(">> wlCommonInit()...");
wl_directUpdateChallengeHandler.handleDirectUpdate = function(directUpdateData,directUpdateContext) {
objectData = directUpdateData;
objectContext = directUpdateContext;
console.log(">>>> Inside wl_directUpdateChallengeHandler function",directUpdateData,directUpdateContext);
//console.log(">>>> JSON Inside wl_directUpdateChallengeHandler function",JSON.parse(directUpdateData),JSON.parse(directUpdateContext));
navigator.notification.confirm(
'Hello World Update',
function(buttonIndex) {
if(buttonIndex == 1){
directUpdateContext.start();
}else{
wl_directUpdateChallengeHandler.submitFailure();
}
},
'Custom Dialog title text',
['Update']
);
};
WLAuthorizationManager.obtainAccessToken()
.then(
function(){
console.log('********Obtained token successfully');
},
function(){
console.log("*****Failed obtaining token");
}
);
}
appcomponent.ts
declare var objectData;
declare var objectContext;
presentAlert() {
let alert = this.alertCtrl.create({
title: 'Update Available',
message: 'Click on the update button to download the latest version',
buttons: [{
text: 'Update',
handler: () => {
console.log(">>>> Handler function alert");
objectContext.start();
}
}]
});
alert.present();
}
在这里,objectContext的值未定义。 反之,如何正确地将上下文传递给js和ts?如何实现这个用例?