Two services are defined in the project, get task
and project
, what if we get their data together in the controller and then assign values? Currently, I use
js
taskService.get({id:id},function(data1){ //... projectService.get({id:id},function(data2){ //里面赋值的操作很长 ... }) })
Could you please tell me how to write the $q method, and I will use this data acquisition operation in many places, how to make them reuse? Thank you
Written according to your requirements, you can see the code below:
If you want to reuse it, you can treat the whole thing as a service. Since I don’t know your specific code, it’s hard to say.
You can add a method to the service, and it will be OK to get two at the same time, for example: