您的位置:首页 > 移动开发

Confirmation on Leaving the Current Page in an Angular.js App

2015-08-20 16:47 495 查看
diagnostic_module.controller("SpeakerCtrler", ["$scope", "$http", function ($scope, $http) {
$scope.isTesting = false;

$scope.$on('$locationChangeStart', function( event ) {
var answer = confirm("Are you sure you want to leave this page?")
if (!answer) {
event.preventDefault();
}
else
{
if($scope.isTesting)
{
$http.delete('/api/diagnostics/speaker').
success(function () {
$scope.isTesting = false;
});
}
}
});

$scope.onStartSubmit = function() {
$http.post('/api/diagnostics/speaker').
success(function () {
$scope.isTesting = true;
});
};

$scope.onStopSubmit = function() {
$http.delete('/api/diagnostics/speaker').
success(function () {
$scope.isTesting = false;
});
};
}]);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: