Requirements: Users can select items for download, so the ID needs to be passed to the backend, but there may be many IDs, so the post request form download is used
Problem: The dom is operated here, so this processing is placed in directive, but aren’t requests generally placed in service? So it’s quite contradictory. Is there any best practice?
高洛峰2017-06-10 09:50:10
First of all, since you have put it in the directive, why not use template to define the template. ?
As for you need to set the value
attribute according to $scope.xxx
, it is easy to solve. There is something called ng-attr
, document: https://docs.angularjs.org/gu...
serviceAren’t requests generally placed in service?
If what you mean by
refers to angular’s service
, then there is no such rule. . . You can encapsulate it into service
or factory
, but there is no problem if you directly use $http
or $resource
in controller
. .