[Solved] Detect if ion-nav-button is shown

I want to hide my menu icon when the back button is shown.

    <ion-nav-bar class="bar-positive">
        <ion-nav-back-button class="button-icon button-clear ion-ios7-arrow-thin-left"></ion-nav-back-button>
    <ion-nav-buttons side="left" ng-if="!isBackButtonShown ">
        <button class="button button-icon ion-navicon" ng-click="toggleMenu()"></button>
    <ion-nav-view name="menu-content"></ion-nav-view>

What can I do in scope.backButtonHidden to detect if the back button is shown or not ? ^^


$ionicNavBarDelegate.showBackButton() returns if the back button is shown or not but how can I update my scope.isBackButtonShown each time the view change ? It would be great to emit an event when the back button is shown or not or to have access directly to its state so we can use the two way data binding.

EDIT 2 :
Here is the solution from here :

$rootScope.$on('$viewHistory.historyChange', function(e, data) {
        $scope.isBackButtonShown = !!data.showBack;

I’m trying to do this but $rootScope.$viewHistory gets ‘undefined’.
That embarassing. But other people signed this.

By the way, the working method to check the state of back button is this:

I did so:

     $rootScope.isBackButtonShown = data.enableBack

in the view:

 <button ng-if="!isBackButtonShown" ng-click="myGoBack()"></button>

that was to hide my custom back button if there is already yhe IONIC one

1 Like