search

Home  >  Q&A  >  body text

angular.js - How to use angular js if there are multiple services?

The background is mainly restful api, for example, there are many taskService, projectService, commentService, etc. I want or get certain data of these three services in one interface, that is, for a task, I want to get comments, project, task content, etc. Detailed information. How to write

in controller
taskService.query({uid:13},function(resource){
            $scope.tasks_list=resource;//获取某条任务的所有信息
        projectService.query({id:resouce.xmid},function(){//在将该信息的项目id传过去
            ...
        })
})

Will this cause nesting?
I hope the masters can give me some ideas~, or is there something wrong with the design from the beginning?

怪我咯怪我咯2774 days ago503

reply all(4)I'll reply

  • 大家讲道理

    大家讲道理2017-05-15 16:53:23

    It is recommended to use the promise solution, which is $q in angular.

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-15 16:53:23

    If there is a correlation between task project comment, it is recommended to encapsulate it on the server and return it through an interface.

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-15 16:53:23

    This should be a server-side problem. If there are needs to call multiple services, it is best to add corresponding server APIs based on these needs. In this way, you can request this API on the front end.

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-15 16:53:23

    The front-end request is asynchronous. It is best to change the API on the server side. If the server side does not change, you can only use Angular's promise here, which is equivalent to converting to a synchronous operation

    reply
    0
  • Cancelreply