Scenario: I have a factory which I use to share data between multiple controllers. In the plnkr, the demo page has two controller and a service is injected in both the controller to share data and do common tasks. Now when I navigate away from demo page to another page and come back, the service still holds old data. I want to dispose the service when I leave the page and get a new copy when I come back. What would be the ideal way to achieve this?
Thanks,
Amit
Pawel Kozlowski
unread,
Feb 4, 2013, 10:54:48 AM2/4/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ang...@googlegroups.com
Hi!
You can't dispose and re-create a service (or factory) - those are
singletons that are created on app's bootstrap.
What you can do, though is to expose a method to clean up your data.
You could call this method by reacting on the $routeChangeSuccess
event, for example.