Skip to content

Commit 07d6003

Browse files
committed
includes code for defer2
1 parent 998a7ef commit 07d6003

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

07-3-promises.html

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
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');
@@ -19,9 +21,30 @@
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'>

0 commit comments

Comments
 (0)