离子2:生成后退按钮单击事件 [英] Ionic 2: Generated back button click event

查看:91
本文介绍了离子2:生成后退按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试记录用户单击导航栏中生成的后退按钮的操作,但我找不到处理点击事件的方法?

I'm trying to log the user's action of clicking the generated back button in the navigation bar, but I can't find a way to handle the click event?

看起来这里的离子导航后退按钮不再起作用了吗?

It seems like the ion-nav-back-button from here isn't working anymore?

推荐答案

根据官方的Ionic docs ,你可以覆盖 backButtonClick() NavBar 组件的方法:

According to the official Ionic docs, you can override the backButtonClick() method of the NavBar component:

import { ViewChild } from '@angular/core';
import { Navbar } from 'ionic-angular';

@Component({
  selector: 'my-page',
  template: `
    <ion-header>
      <ion-navbar>
        <ion-title>
          MyPage
        </ion-title>
      </ion-navbar>
    </ion-header>

    <ion-content>
    ...
    </ion-content>
   `
})
export class MyPage {
  @ViewChild(Navbar) navBar: Navbar;
  constructor(private navController: NavController){}
  ionViewDidLoad() {
    this.navBar.backButtonClick = (e:UIEvent)=>{
     // todo something
     this.navController.pop();
    }
  }
}

这篇关于离子2:生成后退按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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