Ionic 2 自定义后退按钮操作 [英] Ionic 2 customize back button action

查看:16
本文介绍了Ionic 2 自定义后退按钮操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义此屏幕截图中提到的后退按钮的单击操作.我希望通过单击我不会返回上一页而是返回到我自己指定的页面,或者在返回之前进行处理.

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.

推荐答案

要自定义默认后退按钮操作,您需要重写 NavBar 组件的 backButtonClick() 方法.

For customize default back button action you need override the backButtonClick() method of the NavBar component.

第 1 步:在您的 "custom-class.ts" 中导入导航栏组件.创建 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()
       }
    }
}

此代码已在 ionic 3 中测试过.

这篇关于Ionic 2 自定义后退按钮操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆