0

I want to execute a function before the application close. I have a code which is executing before the route changes that is fine, but I also want to execute the same function if someone close the application instead of changes the route..Is there any way?

 $scope.$on('$destroy', function () {

                element.autoSave();

            });
Ammar Khan
  • 2,565
  • 6
  • 35
  • 60
  • 1
    The closest you can get would be subscribe to window.unload event, https://developer.mozilla.org/en-US/docs/Web/API/Window.onunload – Chandermani Apr 05 '14 at 15:05
  • [this post](http://stackoverflow.com/questions/14809686/showing-alert-in-angularjs-when-user-leaves-a-page) may help. – Eliran Malka Apr 05 '14 at 15:32

1 Answers1

2

The "onbeforeunload" event fires before the window starts unloading its resources. More info here: MDN onbeforeunload

Beware of what you do on this handler, as the browser would not complete, for example, an Ajax request before unloading.

GonchuB
  • 705
  • 5
  • 8