Difference between Factory and Service

“Factory” and “Service” are different ways of doing DI (Dependency injection) in angular.

Service Factory
When we define DI using “service” it creates a new GLOBAL instance of the object and injects it in to the function. When you define DI using a “factory” it does not create a instance. It just passes the method and later the consumer internally has to make calls to the factory.
We use it when you need to share a single object across the application. When you define DI using a “factory” it does not create a instance. It just passes the method and later the consumer internally has to make calls to the factory.
We can use it for holding data for authenticated user details. It is just a collection of functions like a class.

results matching ""

    No results matching ""