Difference Between AngularJS Module Factory, Service And Provider




First of all lets consider the Difference among Factory, Service and Provider.
Factory Returns the Function's Return Value. Provider Returns the output of the Function's $Get Function. Service Returns the Actual Function. We explain on the basis of return value of each of them. Lets Consider a common function as shown below. This function will be used in common for Factory, Service and Provider demo.

Difference Between AngularJS Module Factory Service And Provider, Factory Vs Service Vs Provider In AngularJS, Difference Between AngularJS Module Factory And Provider, Difference Between AngularJS Module Service And Provider, Difference Between AngularJS Module Factory And Service




Difference Between AngularJS Module Factory Service And Provider, Factory Vs Service Vs Provider In AngularJS, Difference Between AngularJS Module Factory And Provider, Difference Between AngularJS Module Service And Provider, Difference Between AngularJS Module Factory And Service

Syntax:

module.factory( 'factoryName', function );
Factory Returns the Function's Return Value.

Here the Function's name is demoFunction
The function's return value is Output from Factory is : Technomark.In.
We use double curly bracket for displaying the output as shown below.

{{ FactoryResult }}


The Result will be as follows on the browser.

This is From Factory : Output from Factory is : Technomark.In


That means we get the function's return value on the factory.






Syntax:

module.service( 'serviceName', function );
Service Returns the Actual Function.

Here the Function's name is demoFunction
We use double curly bracket for displaying the output as shown below.

{{ ServiceResult }}



> The Result will be as follows on the browser.

This is From Service : [object Object]


That means, Service Returns the Actual Function..




Difference Between AngularJS Module Factory Service And Provider, Factory Vs Service Vs Provider In AngularJS, Difference Between AngularJS Module Factory And Provider, Difference Between AngularJS Module Service And Provider, Difference Between AngularJS Module Factory And Service

Syntax:

module.provider( 'providerName', function );
Provider Returns the output of the Function's $Get Function .

Here the Function's name is demoFunction
The function's $get function's return value is Output from Provider is : Google.com.
We use double curly bracket for displaying the output as shown below.

{{ ProviderResult }}



The Result will be as follows on the browser.

This is From Provider : Output from Provider is : Google.com


That means, Provider Returns the output of the Function's $Get Function .