javascript 如何在页脚(离子框架)中创建后退按钮?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22739459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to create a back button in the footer (ionic framework)?
提问by thinkbigthinksmall
I'm using Ionic and want to create a back button in the footer. Here's how I'm doing it.
我正在使用 Ionic 并想在页脚中创建一个后退按钮。这就是我的做法。
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?
我的问题:有没有更好的方法来做到这一点(即指令),或者这也是你这样做的方式?
采纳答案by Dev01
With custom click action, using $ionicNavBarDelegate:
使用自定义点击操作,使用 $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/
来自离子文档:http: //ionicframework.com/docs/nightly/api/directive/ionNavBackButton/
回答by Jeferson Rivera
Use the $ionicGoBack
function as the click handler
使用该$ionicGoBack
函数作为点击处理程序
<button class="button" ng-click="$ionicGoBack()">Back</button>
回答by lucasl
You could also just use:
你也可以只使用:
$ionicHistory.goBack();