angularjs - Decoupling between service and controller e.g. not using $http -
i'm quite new angularjs
, i'm trying find nice way implement controller-service communication simple rest
client i'm writing.
on web find lot of examples controller
delegates $http
requests service
still rely on $http
object perform success/error handling. imho not thoroughly decoupled, $http
object "leaked" controller
layer. controller
should ignorant of how data retrieved -- should ask service layer "give me/do this/etc."
i have java
background typically decouple controller-service using pojo's can anti-pattern i've heard.
what best practice?
i returning promises services
. here's example:
controller:
$scope.removetask = function(task) { boardservice.removetask({task_id: task.id}).then(function() { // task removed }); }
service:
this.removetask = function(data) { return $http.post($rootscope.serverroot + '/task/delete', data); }
doing way not require inject $http
in controller.
Comments
Post a Comment