Reputation: 129
I have a simple question about angular life cycle. With my experience, whenever a new view(page) is loaded, angular will create a new controller for that such as a changing of state. And also, whenever I try to refresh the page, the whole module will be refreshed, angular will build a new service. Why does that happens, can someone help me get a documentation about the life cycle of different objects in angular.
Upvotes: 1
Views: 222
Reputation: 21769
In AngularJs, all services are singletons, meaning that until the user refreshes the whole page, each time a service is invoked, it will be the same instance. The only services that does not work this way, are controllers. They are instantiated each time the user navigates inside your app (If the navigation is to a different controller than the actual, otherwise, it will change the state if both states are handled by the same controller).
You can, however, create services that return a new instance of an object each time they get invoked, but the service itself will be a singleton that returns a new instance of a given object upon each invocation.
You can read more about this here
Upvotes: 1