how to create a back button in the footer (ionic f

2019-04-06 09:03发布

I'm using Ionic and want to create a back button in the footer. Here's how I'm doing it.

My view:

  <div class="bar bar-footer bar-dark">
    <button class="button button-outline button-light" ng-click="goBack()"><i class="ion-arrow-left-c"></i> Back</button>
  </div>

and the controller for this view:

$scope.goBack = function () {
    window.history.back();
};

My question: is there a better way of doing this (i.e. a directive), or is this how you are doing this also?

3条回答
Melony?
2楼-- · 2019-04-06 09:26

With custom click action, using $ionicNavBarDelegate:

<button class="button" ng-click="goBack()">Back</button>

function MyCtrl($scope, $ionicNavBarDelegate) {
  $scope.goBack = function() {
    $ionicNavBarDelegate.back();
  };
}

From the ionic docs: http://ionicframework.com/docs/nightly/api/directive/ionNavBackButton/

查看更多
Bombasti
3楼-- · 2019-04-06 09:29

You could also just use:

$ionicHistory.goBack();
查看更多
Juvenile、少年°
4楼-- · 2019-04-06 09:39

Use the $ionicGoBack function as the click handler

<button class="button" ng-click="$ionicGoBack()">Back</button>
查看更多
登录 后发表回答