如何在页脚(离子框架)中创建后退按钮?
问题描述:
我正在使用Ionic并希望在页脚中创建一个后退按钮。这就是我在做的方式。
I'm using Ionic and want to create a back button in the footer. Here's how I'm doing it.
我的观点:
<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>
以及此视图的控制器:
$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?
答
使用$ ionicNavBarDelegate进行自定义点击操作:
With custom click action, using $ionicNavBarDelegate:
<button class="button" ng-click="goBack()">Back</button>
function MyCtrl($scope, $ionicNavBarDelegate) {
$scope.goBack = function() {
$ionicNavBarDelegate.back();
};
}
来自离子文档:
http://ionicframework.com/docs/nightly/api/directive/ionNavBackButton/