Sunday, September 3, 2017

Factory in AngularJS

  • A factory is a simple Javascript function which allows you to add some logic before creating the object. It returns the created object.
  • This is a singleton object .
Syntex: module.factory( 'factoryName', function );
Example:



When to use
  • It is recommended to use Factory in all the cases.
  • It lets you execute any of your complex logic before returning the final object. So, use this whenever your service needs to be a little complex.

No comments:

Post a Comment