2

In Ionic 2 when you use the NavBar, there is a back button automatically added. I want to observe with NG2 if a user clicks on it.

http://ionicframework.com/docs/v2/api/components/navbar/Navbar/

Any ideas how to achieve this?

Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
  • 1
    Its similar to one of my answers ? http://stackoverflow.com/questions/38906715/ionic-2-generated-back-button-click-event/38936466#38936466 – LeRoy Aug 18 '16 at 13:13

2 Answers2

2

Ionic did not expose any API for that, as far as I know.

But since this is Javascript, you can always hack it. You can add a click listener on that button if you know where it is in the DOM:

document.querySelector('ion-navbar button.back-button').addEventListener(event => {
    //do stuff   
});
Yaron Schwimmer
  • 5,327
  • 5
  • 36
  • 59
0

You can override the Navbar ViewChild in your page component

export class MyPage {
     @ViewChild(Navbar) navBar: Navbar;

     constructor(private navCtrl: NavController){}
     ionViewDidLoad() {
         this.navBar.backButtonClick = (e:UIEvent)=>{
         // code here 
         this.navCtrl.pop();
     }
}