[AngularJS] Promises: Chain Promises - 1
Chaining promises
The return value of the then function of the promise is again a promise.(That maybe why in chain promise we can skip new a defer promise, just use $q.resolve()) This allows us to combine or chain asynchronous tasks. We can write
Now we need to define the test2 function in the controller which will be executed whenever the user clicks on the button.
It is important to note that the first on-success function defined on line 25 gets the value ‘Hurray’ injected as defined when resolving the promise. On line 28 we define the return value of the promise which will be injected to the second on-success function defined on line 33. The same is true for the on-failure functions. If we omit to define a return value as on line 28 then the value of the result parameter on line 33 would be undefined.
Without running the application try to determine what message the alert boxes on line 34 and 36 will show.
相关文章
- [Angular] Use Angular components in AngularJS applications with Angular Elements
- [AngularJS] Services, Factories, and Providers -- Service vs Factory
- [AngularJS + Webpack] Using Webpack for angularjs
- [AngularJS] Best Practise - Controller
- [AngularJS] Soup to bits
- AngularJS学习--- 过滤器(filter),格式化要显示的数据 step 9
- [AngularJS] Best Practise - Minification and annotation
- [AngularJS] Promises: Chain Promises - 2. Chaining multiple asynchronous (server-) calls
- [AngularJS] Promises: Chain Promises - 1
- [AngularJS]4. Display more object -- ng-repeat
- [Angularjs]视图和路由(四)
- angularjs开发常见问题-2(angularjs内置过滤器)