-
Notifications
You must be signed in to change notification settings - Fork 0
/
exemplo 12.2 – promises-chain.html
41 lines (38 loc) · 1001 Bytes
/
exemplo 12.2 – promises-chain.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!doctype html>
<html ng-app="myApp">
<body>
<h4>Promise Chain</h4>
<div ng-controller="PromiseChainController">
<ul>
<li ng-repeat="h in hobbies">
Valor recebido na <b>Promise <u>{{$index + 1}}</u></b> => {{h}}
</li>
</ul>
</div>
<script src="angular.min.js"></script>
<script type="text/javascript">
angular.module('myApp', [])
.controller('PromiseChainController', ['$scope', '$q', function($scope, $q) {
// resultado - saída
$scope.hobbies = [];
// defer object
var defer = $q.defer();
// chain
defer.promise
.then(function(hobby){
$scope.hobbies.push(hobby);
return "Ver Filme";
})
.then(function(hobby){
$scope.hobbies.push(hobby);
return "Jogar Futebol";
})
.then(function(hobby){
$scope.hobbies.push(hobby);
});
// inicia chain no primeiro defer.resolve()
defer.resolve("Sair com os Amigos");
}]);
</script>
</body>
</html>