不工作angularjs设备后退按钮 [英] angularjs device back button not working
问题描述
我想,当设备后退按钮点击,搜索互联网和与编码走过来创建对话框。
1.当我用下面的编码,单击后退按钮显示对话框确定,当我点击确定取消:应用程序关闭。
2.当我点击取消:应用程序关闭
app.run(['$ rootScope','$ mdDialog','$ cordovaDialogs',函数($ rootScope,$ mdDialog,$ cordovaDialogs){\r
document.addEventListener(deviceready功能(){\r
的console.log(deviceready);\r
document.addEventListener(后退按钮,onBackKeyDown,FALSE);\r
功能onBackKeyDown(){\r
如果(确认(你确定你想退出?)){\r
的console.log(真);\r
navigator.app.exitApp();\r
}其他{\r
返回false;\r
}\r
}\r
},假);\r
$ rootScope。在$('$ routeChangeSuccess',函数(事件,目前,previous){\r
$ rootScope.title =当前$$ route.title。\r
});\r
}]);
\r
请看看上面的代码,我做错了什么......?我只需要显示设备内准备确认对话框。而取消不得结束应用程序..谢谢你在前进的家伙。
为支撑的家伙,我已经从我的队友们得到帮助完成了这个问题,谢谢..请参阅下面的code ..:)
app.run(['$ rootScope','$位置',函数( $ rootScope,$位置){\r
document.addEventListener(deviceready功能(){\r
的console.log(deviceready);\r
document.addEventListener(后退按钮,onBackKeyDown,FALSE);\r
功能onBackKeyDown(五){\r
亦即preventDefault();\r
如果($ location.path()===/登录|| $ location.path()===/家){\r
变种R =确认(退出);\r
如果(R ==真){\r
的console.log(不退出);\r
navigator.app.exitApp();\r
}其他{\r
navigator.app.goBack();\r
}\r
}其他{\r
/ * $ ionicHistory.goBack(); * /\r
window.history.back();\r
navigator.app.goBack();\r
}\r
}\r
},100);\r
$ rootScope。在$('$ routeChangeSuccess',函数(事件,目前,previous){\r
$ rootScope.title =当前$$ route.title。\r
});\r
}]);
\r
I am trying to create dialog when device back button clicked, searched internet and came up with the coding. 1.when i use the below coding, Clicking back button shows dialog ok and cancel when i click ok:the app closes. 2. when i click cancel: the app closes.
app.run(['$rootScope','$mdDialog','$cordovaDialogs', function($rootScope, $mdDialog, $cordovaDialogs) {
document.addEventListener("deviceready", function() {
console.log("deviceready");
document.addEventListener("backbutton", onBackKeyDown,false);
function onBackKeyDown() {
if(confirm("Are You sure You wanna Exit?")){
console.log("true");
navigator.app.exitApp();
}else{
return false;
}
}
},false);
$rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
$rootScope.title = current.$$route.title;
});
}]);
Please look into the above coding, i am doing anything wrong.. ? I just need to show confirm dialog inside device ready.. And cancel must not end the app.. Thank you in advance guys.
Thanks for the support guys, I have completed this issue by getting help from my mates.. Please see the code below.. :)
app.run(['$rootScope','$location', function($rootScope,$location) {
document.addEventListener("deviceready", function() {
console.log("deviceready");
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
e.preventDefault();
if ($location.path() === "/login" || $location.path() === "/home") {
var r=confirm("exit");
if(r==true){
console.log("not exit");
navigator.app.exitApp();
}else {
navigator.app.goBack();
}
}else {
/* $ionicHistory.goBack(); */
window.history.back();
navigator.app.goBack();
}
}
}, 100);
$rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
$rootScope.title = current.$$route.title;
});
}]);
这篇关于不工作angularjs设备后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!