質問

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