javascript - angular form submission about directive and service
typecho
typecho 2017-06-10 09:48:10
0
1
768

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?

typecho
typecho

Following the voice in heart.

reply all(1)
小葫芦

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...

Aren’t requests generally placed in service?

If what you mean by
service

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. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!