10

In an MVC framework, the data are handled in the model.

In AngularJs, is it common to handle the data directly in a controller, or should it be done in a service instead?

JMaylin
  • 1,378
  • 4
  • 15
  • 38
  • Best practice would be storing data in a service. But if it's just small amount of data and the data is not used in other places, controller is fine. – Daiwei Sep 27 '13 at 16:27
  • @sza This is an interesting post, but that doesn't really answer my question – JMaylin Sep 30 '13 at 07:35

1 Answers1

6

There is no harm in firing XHRs from within a controller if controller is the only one using the call.

But if multiple controllers need to make the same call you would better move it inside a service for ease of access.

AlwaysALearner
  • 43,759
  • 9
  • 96
  • 78
  • This is what I do, I just wanted to know what purists think about it. Thank you for your answer. – JMaylin Sep 30 '13 at 07:48
  • u said move ajax call in service due to ease of access. why not to move the ajax call in factrory.....please tell me the reason why avoid factor for this purpose? – Monojit Sarkar Jun 12 '17 at 14:11