search

Home  >  Q&A  >  body text

javascript - angular form submission about directive and service

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?

typechotypecho2732 days ago803

reply all(1)I'll reply

  • 高洛峰

    高洛峰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...

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

    reply
    0
  • Cancelreply