angular.js - angular js 如果有多个服务,应该如何用呢?
怪我咯
怪我咯 2017-05-15 16:51:23
0
4
490

后台主要是restful api ,比如有很多taskService,projectService,commentService等等,我在一个界面要或去这三个服务的某些数据,就是一个任务要获取 评论,所属项目,任务内容等等详细的信息。在controller中该如何去写

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

这样是不是会陷入嵌套?
望大神们给点思路啊~,还是说一开始的设计就有问题?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
大家讲道理

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

漂亮男人

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

滿天的星座

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.

大家讲道理

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template