Just wondering what is the best way to go about implementing something similar to a global controller?
I have an $interval that runs in my app runs every 20s, however I cannot put this code in a controller obviously because when I move to another view the controller’s scope will be destroyed.
So do I:
Add the $interval to run method in the app.js
Create a parent controller that wraps around the whole app? (That feels yuck just thinking that).
Or do I somehow not destroy the controller that currently has the $interval in it when that view is exited, if that makes sense.
Indeed you can pass the interval function to a variable, as long as the variable is not set to undefined and cancel using the $interval, it will keep on running.
So what you may need to concern is that how to close the unused interval instead of worrying about if the interval is canceled after the scope is destroyed.
My solution is to give it to an Angular Service object which may be accessible across the app and I can cancel it and start it at anytime and any place.