2

https://github.com/johnpapa/angular-styleguide#style-y060

Shows a single responsibility factory making $http requests and handling some logic and errors, returning the promise. Typically from there, I would store the results in a service (as opposed to controller $scope so I can access it anywhere, including in directives). However:

Conversely, don't create a service whose only purpose in life is to store and return bits of data.

https://docs.angularjs.org/misc/faq

Should I store the data on the factory itself? Or continue with factory -> http / service -> storage?

I'm not asking what the code difference is between the two, "one can be new'd etc", I'm asking for those that follow Angular best practices (skinny controllers, etc) what are the rules concerning the roles of a factory after it's fetched the data?

iksose
  • 229
  • 1
  • 8
  • possible duplicate of [Service vs provider vs factory?](http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory) – Matthew Green Mar 30 '15 at 19:29

1 Answers1

1

Should I store the data on the factory itself? Or continue with factory -> http / service -> storage?

I see nothing wrong here. And don't forget, there are constant and value that fit nicely to 'store and return bits of data'. And caching solutions (i.e. $cacheFactory, angular-cache) that can help you to improve app design.

You can't blame Angular FAQ for advocating $rootScope, but keep in mind that it could be an obsolete opinion of some team member. Things have changed in Angular, and opinions have also changed in Angular community. You shouldn't trust a single developer on how exactly you should write your code (even if Papa is the surname), but it surely wasn't he who introduced the questionable concept of 'scope' into JS framework that was later anathematized even by its creator.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565