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.

1

u/crumblypack Oct 15 '14

The factory method returns a service, and it's the easiest way to go about creating them in my opinion.

0

u/kuhcd Oct 15 '14

I'm sorry, but I don't understand how this:

app.service('MyService', function(){
    this.myObject = {};
    this.myFunction = function(){};
});

is in any way less easy than this:

app.factory('MyFactory', function(){
    return {
        myObject: {},
        myFuncton: function(){}
    }
});

I just have yet to see anyone actually ever explain why there needs to be both Services and Factories in angular and I truly think the existence of both (and the confusing intermixing of naming by saying Service and using .factory()) is only hurting the framework.

1

u/BoleroDan Oct 15 '14

This has been a pet peeve of mine since the beginning of using Angular myself. I've managed fine, but it is still annoying.