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

来源:互联网 发布:网络布线是做什么的 编辑:程序博客网 时间:2024/06/07 07:22
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;        });    };}]);

0 0