I am a jquery developer, now I am learning angularJS through tutorials point, I didn't understand the concept of the angularJS service and factory. Please advise me where can I get exact details on this.
Advance thanks.
I am a jquery developer, now I am learning angularJS through tutorials point, I didn't understand the concept of the angularJS service and factory. Please advise me where can I get exact details on this.
Advance thanks.
If you don't have a fundamental understanding of MVC frameworks, I would recommend first understanding the Model-View-Controller concept. Assuming you have an understanding of MVC:
Both sort of act as your 'models'. Ultimately, if you so choose, you can use either or in most cases. However, the main difference between a service and a factory is that a factory is intended to return an object, that you will interact with. Whereas a service actually gets initialized using this
, and you will interact with the service using it's namespace followed by an attribute on the service.
I reccommend the article below. It really helps highlight on the difference in a way that's easy for angular newbies. I find myself referring to it from time to time, and it's currently the top result on google. Check er out,
http://tylermcginnis.com/angularjs-factory-vs-service-vs-provider/
At the end of the day, I typically find myself using services more. The use cases will vary, and like I said earlier, in most basic applications there is a good chance you could get away with using either/or.
Providers on the other hand are intended to be used quite a bit differently. Refer to the article though, as he does a much better job of explaining the nuances.