Ionic 2自定义后退按钮动作 [英] Ionic 2 customize back button action
问题描述
我想自定义此屏幕截图中提到的后退按钮的单击操作。我希望通过点击我不会返回到上一页,而是返回到我自己指定的页面,或者在返回之前进行处理。
I want to customize the click-action of the back button mentioned in this screen capture. I want that by clicking I do not return to the previous page but to a page that I specify myself, or do a treatment before going back.
推荐答案
对于自定义默认后退按钮操作,您需要覆盖 backButtonClick()方法NavBar组件。
For customize default back button action you need override the backButtonClick() method of the NavBar component.
第1步:在custom-class.ts导入Navbar组件中。创建auxMethod以覆盖默认行为并在ionViewDidLoad方法中调用。
Step 1: In your "custom-class.ts" import Navbar component. Create auxMethod for override the default behavior and called in your ionViewDidLoad method.
import { Navbar } from 'ionic-angular';
import { ViewChild } from '@angular/core';
export class myCustomClass {
@ViewChild(Navbar) navBar: Navbar;
ionViewDidLoad() {
this.setBackButtonAction()
}
//Method to override the default back button action
setBackButtonAction(){
this.navBar.backButtonClick = () => {
//Write here wherever you wanna do
this.navCtrl.pop()
}
}
}
此代码已经过离子3测试。
这篇关于Ionic 2自定义后退按钮动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!