File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change 1010
1111 app . controller ( 'BasicCtrl' , function ( $scope , $q ) {
1212 var defer = $q . defer ( ) ;
13+ //we create a defer object
1314
15+ //we promise a few functions using .then()
1416 defer . promise
1517 . then ( function ( ) {
1618 console . log ( 'hello' ) ;
1921 console . log ( 'world' ) ;
2022 } ) ;
2123
22- defer . resolve ( ) ;
24+ //we then resolve the promises using .resolve()
25+ defer . resolve ( ) ;
26+
27+
28+
29+ var defer2 = $q . defer ( ) ;
30+
31+ //promise a few functions
32+ defer2 . promise
33+ . then ( function ( name ) {
34+ //this function processed the name
35+ return name . split ( '' ) . reverse ( ) . join ( '' ) ;
36+ //what is returned here will be passed to the next promise
37+ } )
38+ . then ( function ( processedName ) {
39+ //this function alerts the user
40+ alert ( 'Your name reversed is ' + processedName ) ;
41+ } ) ;
42+
43+ //here we pass in the first parameter (i.e the persons name)
44+ defer2 . resolve ( 'John Snow' ) ;
45+
46+
2347 } ) ;
24-
2548</ script >
2649</ head >
2750< body ng-app ='app '>
You can’t perform that action at this time.
0 commit comments