Back to Blog

AngularJS Tutorial | Learn To Create Factory | Use Of Factory

AngularJS 1.5 – Factory AngularJS is one of the popular framework of JavaScript. Nowadays it going so popular for front-end development. For this blog you must have basic knowledge about AngularJS. How modules and controllers are make and work in angular ? you need to know first that. In AngularJS, services are used for sharing data […]

AngularJS Tutorial | Learn To Create Factory | Use Of Factory

AngularJS 1.5 - Factory


AngularJS is one of the popular framework of JavaScript. Nowadays it going so popular for front-end development.



For this blog you must have basic knowledge about AngularJS. How modules and controllers are make and work in angular ? you need to know first that.


In AngularJS, services are used for sharing data among more than 2 controllers or modules. means that share one controller value with another controller. You can also make one service for your main parent app module that is share with all child app or controller.


In AngularJS between factory and services there are a little bit difference exist and that is TYPE. Yes, Factory uses json array type response where Service uses object type. Further in this blog you can see how factory work.


Now let's create Service in AngularJS 









Here, in above image you can see that how Factory Service  is created using module. You can create service at creation of app module or using object of app module. Both ways are supported.


In this service you can see that there are a json array named itemList . That contain shared data. Means when one controller update new data then that data assign to this service variable then in further process when other controller need that data then they retrieve updated data from service variable.


After creating service and its task now its time to bind or use within controller,





Here, check out how service name used with controller. How service pass to controller and use of it.

Now whenever you need of this created service you just need to pass that service name to controller. For this created service you do not need to write again.

When you update your data then also update service data if your data use with other controller or app module, then in other controller use function for retrieving latest data.


Thank You.