Angularjs 如何在phonegap移动应用程序中同步android中的离子导航栏和硬件按钮
在我的Angularjs 如何在phonegap移动应用程序中同步android中的离子导航栏和硬件按钮,angularjs,ionic-framework,phonegap-build,Angularjs,Ionic Framework,Phonegap Build,在我的phonegap应用程序中,有一个带有后退按钮的离子导航栏。如果我们使用此导航栏导航应用程序,它将正确导航到每个页面,但如果我们在某个时间点使用硬件后退按钮,导航将变得混乱。这有什么解决办法吗 <ion-view view-title="Store Locator" ng-controller="storelistCtrl" > <ion-nav-buttons side="right"> <button form="searchId
phonegap
应用程序中,有一个带有后退按钮的离子导航栏。如果我们使用此导航栏导航应用程序,它将正确导航到每个页面,但如果我们在某个时间点使用硬件后退按钮,导航将变得混乱。这有什么解决办法吗
<ion-view view-title="Store Locator" ng-controller="storelistCtrl" >
<ion-nav-buttons side="right">
<button form="searchId" class="button button-icon icon ion-ios7-search" ng-click="search(searchForm.searchText)"></button>
</ion-nav-buttons>
<ion-content>
some code here....
</ion-content>
</ion-view>
在实施之前,先检查文档 可供选择的有
确保首先调用$ionicPlatform.ready() 您需要使用$ionicPLatform.registerBackButtonAction来执行此操作,根据状态重定向,但您需要确保首先调用$ionicPLatform.ready(),请参见下面的代码
$ionicPlatform.registerBackButtonAction(function (event) {
if ($state.$current.name=="app.login" || $state.$current.name=="app.signup"){
// Do not go to the previous state (or view) for these states.
// Do nothing here to disable H/W back button.
$cordovaDialogs.alert('Going back is not allowed for this page', 'Notice', 'OK')
.then(function() {
// callback success
});
}
else if($state.$current.name=="app.productlist")
{
$location.path("/productlist");
} else {
// For all other states, the H/W BACK button is enabled
navigator.app.backHistory();
} }, 100);
请在您的问题中添加一些代码。我尝试了这个问题,但它与$location.path()无关;重定向到指定页面。当我添加setTimeout时(function(){window.location.href=“#/app/home”;},0);页面正在重定向到指定页面,但具有闪烁效果;因为它将进入上一页,然后返回。我们如何避免这种情况?不要使用window.location.href,因为它会在每次调用时重新初始化整个应用程序。而是使用$state.go(“productlist”);在控制器中,ionic使用ui路由器在angular.js中进行路由。为了便于参考,我在registerBackButtonAction中尝试了$state.go(“app.home”),但它没有重定向到指定的页面。你能帮我一下吗..你需要在控制器中添加一个依赖项才能使它工作,请确保$state或$location在你的控制器依赖项中
$ionicPlatform.registerBackButtonAction(function (event) {
if ($state.$current.name=="app.login" || $state.$current.name=="app.signup"){
// Do not go to the previous state (or view) for these states.
// Do nothing here to disable H/W back button.
$cordovaDialogs.alert('Going back is not allowed for this page', 'Notice', 'OK')
.then(function() {
// callback success
});
}
else if($state.$current.name=="app.productlist")
{
$location.path("/productlist");
} else {
// For all other states, the H/W BACK button is enabled
navigator.app.backHistory();
} }, 100);