cleaning up services

68 views
Skip to first unread message

Jake Kwon

unread,
Mar 12, 2014, 4:44:23 PM3/12/14
to ang...@googlegroups.com

Hello,

I am using services to share data across multiple controllers. But I noticed
that when I logout and log back in the data in my services still has data from the previous session.

How can I properly clean up my services after I finish a session?

Thanks

PS: my service looks like this

app.factory('UserModel', function(){
  var user = {
    id: '',
    profile: {}
    ...
  }

  return user;
});

Sander Elias

unread,
Mar 13, 2014, 2:13:32 AM3/13/14
to ang...@googlegroups.com
Hi Jake,

Refresh your browser on log-out. Services are singletons, and they keep their value as long as those are alive. 

Regards
Sander

J Kwon

unread,
Mar 13, 2014, 12:14:43 PM3/13/14
to ang...@googlegroups.com
Hey, Sanders Elias

Thanks for your answer.

When you said 'Refresh your browser on log-out', you mean refresh manually? ( e.g. by pressing the keyboard's f5 button)?

If this is what you meant, I do not desire the user to do that whenever they log out from the app.

Thanks


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/3lUbnjwy_fA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Mar 13, 2014, 12:52:55 PM3/13/14
to ang...@googlegroups.com

Hi Jake,

No, you can’t ask a user to do that. Do a window.location.reload(true); just after your logout code.

Regards
Sander

J Kwon

unread,
Mar 13, 2014, 2:08:36 PM3/13/14
to ang...@googlegroups.com
Hello, Elias

Thanks again for your answer, 

Actually I looked at the $route.reload() function, which does the same in an angular fashion.

Just out of curiosity, is there any reason why you recommended me to use 'window.location.reload(true)' over the $route.reload() ?

Thanks




--
Reply all
Reply to author
Forward
0 new messages