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?
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();
}
}
}