对于自定义默认后退按钮操作,您需要覆盖NavBar组件的backButtonClick()方法.
第1步:在“custom-class.ts”中导入Navbar组件.创建auxMethod以覆盖默认行为并在ionViewDidLoad方法中调用.
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中进行了测试.