hiding back button in ionic, angularjs

2019-01-17 04:13发布

I need to show and hide back button in different pages/views. I took reference from Justin Noel:

<body ng-app="starter" ng-controller="AppCtrl">
  <ion-nav-bar class="bar-stable">
    <ion-nav-back-button hide-back-button="{{hideBackButton}}">
    </ion-nav-back-button>
  </ion-nav-bar>
</body>

App controller to toggle button display:

.controller('AppCtrl', function($scope, $location) {
   var path = $location.path();
   if (path.indexOf('submit') != -1)
     $scope.hideBackButton = true;
   else
     $scope.hideBackButton = false;
})

But this doesnt work as controller is called only once but not at the change of view in different states. Also changing the value of $scope.hideBackButton from other controllers(linked to different states) does not have any effect on the button display.

Can anyone tell me how to toggle back-button display on each navigation. What am I missing here?

9条回答
成全新的幸福
2楼-- · 2019-01-17 04:38

You can change the cache settings so that when the page is reloaded the controller is called again: http://ionicframework.com/docs/api/directive/ionNavView/

查看更多
Rolldiameter
3楼-- · 2019-01-17 04:39

The hide-back-button attribute on <ion-view> did the trick for me: <ion-view hide-back-button="true">

See the official documentation here.

查看更多
看我几分像从前
4楼-- · 2019-01-17 04:40
$ionicHistory.nextViewOptions({
    disableBack: true
  });

  $state.go('app.home');
查看更多
太酷不给撩
5楼-- · 2019-01-17 04:42

A very simple way to achieve this is to apply the menu-close directive to your button/anchor. Technically it's meant for closing the menu, but you can use it on any link and it will bypass the slide animation & won't show the back button.

<a menu-close href="#/home">Home</a>

http://ionicframework.com/docs/api/directive/menuClose/

查看更多
啃猪蹄的小仙女
6楼-- · 2019-01-17 04:43

Ionic 2 & 3: <ion-navbar [hideBackButton]="true">

查看更多
时光不老,我们不散
7楼-- · 2019-01-17 04:43

The hide-back-button attribute should be set on ion-view tag.

查看更多
登录 后发表回答