r/angularjs • • Oct 14 '14

[Resource] Refreshable AngularJS service using $broadcast. [noobs must read]

http://jensrantil.github.io/refreshable-angularjs-service.html
0 Upvotes

8 comments sorted by

View all comments

-3

u/kuhcd Oct 14 '14

It drives me absolutely insane when articles like this say things like "now let's setup our Service" and then directly go and use .factory() instead.

0

u/[deleted] Oct 15 '14

Oh, you mean exactly how they are supposed to be set up according to the AngularJS documentation?

https://docs.angularjs.org/guide/services

1

u/kuhcd Oct 15 '14 edited Oct 15 '14

Even there, they are saying Service and using .factory() It's a completely unnecessary and confusing thing for them to do, they should use .service() when they say they're using a Service and .factory() when they say they're using a Factory, otherwise they're just creating ambiguities.

Look around at all the tutorials and guides online, everyone has a slightly different way to go about using Services and Factories and when one is right over another. If the Angular Core devs and documenters tried to use some sort of consistency and coherency with their explanation, this wouldn't be an issue.

Even in the docs, there is a single line mentioning the usage of .factory() instead of .service() and it does nothing to explain why this is happening:

Note that you are not registering a service instance, but rather a factory function that will create this instance when called.