I am new to Angular and trying to clear my concepts:
My app requires a single model which will be updated by different controllers. So, the model should be shared. Following link explains clearly how should I proceed with it
http://www.webdeveasy.com/angularjs-data-model/
It creates two services using factory method. The manager service checks whether the model class has been already instantiated or not. If yes it returns an already instantiated reference otherwise it new's
an instance. Hence each model sees the same model instance and on updating model updates occur in all the views.
If instead of creating service using factory
, one creates a service using service
method which returns a new'd
instance automatically, would that be shared or bound to the controller.
I assume my case cannot be achieved using service
method, i must use factory
method instead of service
method as it new's
the services everytime it is injected in any controller. Does angular not maintain some pool internally to make sure same service instance is injected in all the controllers.
I don't want an additional manager object for the model to ensure same instance being used in all the controllers