I return to the following three links when I need to refresh my memory or explain to someone else the differences. They have served me well as the first one is participated in by Miško Hevery. The first link is gold where Miško answers and expands a bit.
- Angular Mailing List
- Xebia Blog Post
- StackOverflow Answers
- Angular Documentation (much improved as of May 2014)
There is one more SO link that has an even better answer than the on provided but I’ll have to ask my co-worker on monday for it. It’s better because it answers the ‘why’ one is different and this shows how without code examples which always confuse me. Then it sums up with a very simple chart at the bottom. I would look for it right now but my H is is asking why it takes so long to leave a note :-) Hacker News is not letting one leave comments right now so I’m putting this here since I want to expand on it with the link from Tsanko next week. Ok, she just said “c’mon daddy its your turn.’ rolled her eyes and followed up with “Shouldn’t you be here? It’s your turn.” Turns out I lost the scrabble game anyway - 16 triangles to 10 because in this version one gets a triangle for completing preset words on the board in order of letters. Weird, so Monday when I talked to T, we looked at SO together and he was just as confused as I was. The original answer we both liked for its clarity was gone. While the existing answers are good they are all similar to the “explanation with an example.” I much prefer an explanation with here is how fundamentally they differ and why that matters without code. Oh well, the link to the angular mailing list is a welcome addition. It would be nice if the original form of the answer that clicked with my mind had been preserved. Fair enough H. I’ll come back to this later … As the night nights pass and children sleep, I come back to this though in the morning and roughly I remember the table data points as thus (also stealing a bit from the first link above so I can just come here):
Services
- Are Singletons
- Invocation: returns new instances of its functions (ie invoking myService.myFn() returns a new instance of the function in MyService)
- Cannot be configured during angular config phase
Factories
- Are Singletons
- Invocation of myFactory.myFn() returns a value from the Fn referenced
- Cannot be configured during angular config phase
Providers
- Are Singletons
- Invocation: returns? ‘you are provided with a new ProviderFn().$get() -> constructor fn is instantiated before $get() is called
- Can be configured during the modules config phase.
I did find a useful table taken from #4 from the list at the top of this post: 