There are three steps
step1: $http.jsonp(url1)
step2: $http.jsonp(url2)
step3: assignment operation,
There is no order requirement for steps 1 and 2. 3 is required to be executed after steps 1 and 2 are completed;
Because steps 1 and 2 will be called in many places, we don’t want it to be
步骤1.success{
步骤2.success{
步骤3}} 这样的写法
I hope to encapsulate steps 1 and 2 into a public method, and then execute step 3 sequentially. How should I write it in angularjs
Use events. Don’t use nesting
Use the $q service that comes with ng
The author can learn about $q and promise objects. As shown above, Angular has $q.all(), which you can use.