Ionic2 点击ionic 2 RC.1后退按钮调用自定义函数
如何在特定页面上单击Ionic 2中的后退按钮调用函数 我脑海中有以下情景。假设我的导航方式如下所示:Ionic2 点击ionic 2 RC.1后退按钮调用自定义函数,ionic2,Ionic2,如何在特定页面上单击Ionic 2中的后退按钮调用函数 我脑海中有以下情景。假设我的导航方式如下所示: PageA --> PageB --> PageC --> PageD 现在,当我单击PageD上的后退按钮时,我想返回到PageB,而不是PageC。我想在点击后退按钮时调用下面的函数 goBack(){ this.navCtrl.popTo(PageB); } 我是这样做的: ionViewDidEnter(){ this.bindMethodToEl
PageA --> PageB --> PageC --> PageD
现在,当我单击PageD
上的后退按钮时,我想返回到PageB
,而不是PageC
。我想在点击后退按钮时调用下面的函数
goBack(){
this.navCtrl.popTo(PageB);
}
我是这样做的:
ionViewDidEnter(){
this.bindMethodToElement('back-button',this.goBack);
}
bindMethodToElement(elementClassName,functionToBind){
try{
let elements = document.getElementsByClassName(elementClassName);
let currentElement : Element = elements[elements.length - 1];
currentElement.addEventListener("click",functionToBind);
}catch(exception){
console.log(exception.message);
throw exception;
}
}
有人知道更好的方法吗。我还想在用户单击设备后退按钮时实现类似的行为。这样的功能已经报告给了爱奥尼亚团队,他们正在验证它。同时,您可以使用以下解决方法:
goBack(){
this.navCtrl.popTo(PageB);
}
goBack(){
this.navCtrl.pop().then(() => {this.navCtrl.pop()});
}
丑陋的解决方案,但有效。祝你好运