Saturday, March 9, 2013

Services and factories, oh my...

The docs are clear about the syntactical difference between, services and factories, and they are similar in that they allow you to abstract javascript functions into discrete testable units. 

In this jsfiddle, a service and a factory are used to output 'hello world'...  So are there specific cases where one would choose one over the other?

It appears the Factory returns a service function, but the factory itself only runs only once. A service runs each time it's called. So if you have some heavy data that you need to load, you can do it in a factory, before you return your service, and you don't have the performance hit every time you use it...

 

No comments:

Post a Comment