To promote code reusability Angular supports the ability to inject reusable services. There are three main ways to inject services into angular controllers, all of which are singleton objects and is the same instances being injected every time.


When a factory instance is created properties/methods assigned to the object, and the object is injected into the angular controller. The following code shows how a factory instance is defined:

angularApp.factory('factory_name', () => {
	var instance = {};
	return instance;


When a service is created 'new' syntax is used. The properties/methods are assigned to this, and 'this' is returned/injected instance.

angularApp.service('service_name', () => {
	/*when service is declared 'new' is used meaning in the background*/
	var obj = Object.create(...);
	this = obj;
	return this;


This is the only angular type can be injected into the angularApp.config(). Use this type when you need a service to alter service(provider) in angularApp.config() before the provider instance is injected to Angular controllers.

angularApp.provider('providerName', () =>{ ... });
angularApp.config((providerInstance) => { ... });
angularApp.controller('controllerName', (providerInstance) =>{ ... })