我在ionic 3中遇到了inappbrowser的问题。在下面的代码中,如果付款成功,我想转移到Thankyoupage,否则它必须留在同一页面上。付款成功或失败后,在关闭inappbrowser后,它将返回到同一页面。我可以调用this.navCtrl.push(ThankyouPage)。我看到了未定义的异常。谁能指导我了解我在哪里犯错了
let option = 'location=no,hidden=yes';
let url = "https://www.example.com/pay;
const browser = this.inappBrowser.create(url,option);
browser.on('loadstart').subscribe(function(event) {
if(event.url== "https://www.example.net/success.php"){
browser.close();
//failuring here
this.navCtrl.push(ThankyouPage);
}
if(event.url== "https://www.example.net/failure.php"){
browser.close();
}
});
答案 0 :(得分:0)
let self=this; // add this line
let option = 'location=no,hidden=yes';
let url = "https://www.example.com/pay;
const browser = this.inappBrowser.create(url,option);
browser.on('loadstart').subscribe(function(event) {
if(event.url== "https://www.example.net/success.php"){
browser.close();
//failuring here
self.navCtrl.push(ThankyouPage); // Update this statement
//self.navCtrl.push('ThankyouPage'); // Uncomment this if you use lazyloading
}
if(event.url== "https://www.example.net/failure.php"){
browser.close();
}
});