Ok, i have got a little further with this: So i have defined a controller 'AppController' that i have associated with my main application div:
<div ng-app="app" ng-controller="AppController" ng-init="startup()"> In my startup() method i bind to the 'beforeunload' event on $window for some last minute processing. Along with $window i inject $cookieStore and $cookies into my controller and through debugging and console logging i can see $cookies object filling up with values through direct manipulation on my page (by using call to $cookiesStore.put()). By pressing the browser refresh button i successfully trigger a call to my 'beforeunload' processing function. Within this handler i can see that the $cookies content reflects the changes made so far, in this handler i modify its content further with another call to $cookiesStore.put() and before leaving this handler i can confirm the $cookies object has been updated accordingly. When a subsequent call to my startup() method is made when ng-init is processed (when the page reloads) the $cookies object content reflects the content before the 'beforeunload' handler call. This would suggest that the $cookies object in the handler was a temporary copy of the actual $cookies object and its content was not written to the cookie file. I can put together a plunk if anyone would be willing to take a look but as a newbie to angular + javascript and web development in general i wondered if I am on the right track with this approach? Many thanks On Wednesday, January 22, 2014 5:01:20 PM UTC, Gary Cuthbert wrote: > > Hello, > > I am currently investigating the use of $cookieStore to record some > trivial application settings and would like to update the $cookieStore when > the application is going through the process of tear down (either when the > user hits the browser reload button or closes the window or navigates away > from the application). > > Is this possible? I have a controller associated with my main <div > ng-app="app"> element and I have tried trapping for $destroy in this > controller and attempting the updates in its handler but the event is not > trapped. > > I could update the $cookieStore periodically in this case but i suspect > sooner or later i will need to be able to perform application cleanup logic > so in general how would/can you detect that an angular application is about > to close? > > Many thanks > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
