我试图将ng-click="ionic.Platform.exitApp()"
设置为按钮但是它已经工作了,我还尝试了ng-click="exitApp()"
和ng-click="$ionic.Platform.exitApp()"
但它没有工作任
我正在使用Ionic Creator,根据此文档http://ionicframework.com/docs/api/utility/ionic.Platform/,它应该非常简单,但我不知道如何正确设置此调整。我还尝试将模块添加到Ionic Creator中:
angular.module('app.exit', []).exit(function($scope) {
ionic.Platform.ready(function(){
// will execute when device is ready, or immediately if the device is already ready.
});
var deviceInformation = ionic.Platform.device();
var isWebView = ionic.Platform.isWebView();
var isIPad = ionic.Platform.isIPad();
var isIOS = ionic.Platform.isIOS();
var isAndroid = ionic.Platform.isAndroid();
var isWindowsPhone = ionic.Platform.isWindowsPhone();
var currentPlatform = ionic.Platform.platform();
var currentPlatformVersion = ionic.Platform.version();
ionic.Platform.exitApp(); // stops the app
});
添加此模块控制台日志打印:"退出不是函数"
由于
答案 0 :(得分:0)
您可以随时尝试使用此ExitApp Plugin
要使用,请按cordova plugin add cordova-plugin-exitapp
添加插件,然后将以下代码添加到app.js
angular.module('XYZApp', ['ionic'])
.run(function($ionicPlatform, $ionicHistory, $rootScope) {
$ionicPlatform.ready(function() {
// For exit on back button press
$ionicPlatform.registerBackButtonAction(function(e) {
if ($rootScope.backButtonPressedOnceToExit) {
navigator.app.exitApp(); // or // ionic.Platform.exitApp(); both work
} else if ($ionicHistory.backView()) {
$ionicHistory.goBack();
} else {
$rootScope.backButtonPressedOnceToExit = true;
// "Press back button again to exit" : show toast
setTimeout(function() {
$rootScope.backButtonPressedOnceToExit = false;
}, 2000); // reset if user doesn't press back within 2 seconds, to fire exit
}
e.preventDefault();
return false;
}, 101);
});
}
答案 1 :(得分:0)
感谢Chiragh Dewan,
但它也无法工作,我补充说:
angular.module('XYZApp', []).run(function($ionicPlatform, $ionicHistory, $rootScope) {
$ionicPlatform.ready(function() {
// For exit on back button press
$ionicPlatform.registerBackButtonAction(function(e) {
if ($rootScope.backButtonPressedOnceToExit) {
navigator.app.exitApp(); // or // ionic.Platform.exitApp(); both work
} else if ($ionicHistory.backView()) {
$ionicHistory.goBack();
} else {
$rootScope.backButtonPressedOnceToExit = true;
// "Press back button again to exit" : show toast
setTimeout(function() {
$rootScope.backButtonPressedOnceToExit = false;
}, 2000); // reset if user doesn't press back within 2 seconds, to fire exit
}
e.preventDefault();
return false;
}, 101);
});
}
);
...进入名为exit.js的新JS文件 然后我将模块XYZApp添加到Ionic Creator代码设置Angular模块中 最后一步我添加了cordova-plugin-exitapp
我试过ng-click =" navigator.app.exitApp()"和ng-click =" ionic.Platform.exitApp()"并且它们似乎都不起作用。
你可以在这里看到项目:https://creator.ionic.io/share/html/2d9b0126751e#/menu/contacto
由于