문제

I need call an AngularJS function when a window goes to close. I have this code now:

app.controller("reportCtrl", function($scope, $http) {

$scope.deleteReport = function() {
    $http.get("/SCTrakker/api/deleteReport").success(function() {
    });
};

window.onbeforeunload = function(){
  $scope.deleteReport();  
}; });

This controller and angular libraries are loaded successfully, that's not the problem. The problem is where i go to close the window not execute the event and does nothing. I don't have any idea what i can to do more.

Thanks to all!

도움이 되었습니까?

해결책 2

The problem has been resolved!

As my problem was that I could not use AngularJS to call the server, what I did was make that call with AJAX and now works perfectly!

다른 팁

You can bind on window close event with JQuery and call your function.

$(window).bind("beforeunload", function() { 
    $scope.deleteReport();
})

Or you can try to use $locationChangeStart event.

$scope.$on("$locationChangeStart", function(){
    $scope.deleteReport();
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top