Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it "best practice" to do an AJAX call from a controller? [duplicate]

Tags:

angularjs

mvvm

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?

like image 440
JMaylin Avatar asked Sep 27 '13 13:09

JMaylin


1 Answers

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.

like image 128
AlwaysALearner Avatar answered Oct 18 '22 04:10

AlwaysALearner