Skip to content

Commit 1c02020

Browse files
committed
promises (chaining promises)
1 parent 45dc8a6 commit 1c02020

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

egghead/index.html

+1-15
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,10 @@
1111
<h1>Angular</h1>
1212

1313
<div ng-app="app">
14-
15-
<input type="text" ng-model="model.prop1"> <br/>
16-
<input type="text" ng-model="model.prop2"> <br/>
17-
<input type="text" ng-model="model.prop3">
18-
19-
<zippy attrfoo="{{model.prop1}}" attrbar="{{model.prop2}}"> <!-- grabs data from chrisProp -->
20-
<!-- NOTE: content that is transcluded has access to parent scope.
21-
This is how model.content is available to the view
22-
-->
23-
<p>Third input is : "{{model.prop3}}". First input is "{{model.prop1}}".</p>
24-
</zippy>
25-
14+
<div ng-controller="AppCtrl"></div>
2615
</div>
2716

28-
2917
<script src="js/angular.js"></script>
3018
<script src="js/app.js"></script>
31-
32-
3319
</body>
3420
</html>

egghead/js/app.js

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
// Define an App
22
var app = angular.module('app', []);
33

4-
app.directive('zippy', function() {
5-
return {
6-
restrict: 'E',
7-
transclude: true,
8-
scope: {
9-
attrfoo: '@',
10-
attrbar: '@'
11-
},
12-
templateUrl: 'templates/zippy_template.html',
4+
app.controller('AppCtrl', function($scope, $q) {
135

14-
link: function(scope) {
15-
scope.isContentVisible = false;
6+
var defer = $q.defer();
167

17-
scope.toggleContent = function() {
18-
scope.isContentVisible = !scope.isContentVisible;
19-
console.log('toggleContent Fired');
20-
};
8+
defer.promise
9+
.then(function(weapon) {
10+
alert('You can have my ' + weapon);
11+
12+
return 'bow';
13+
})
14+
.then(function(weapon) {
15+
alert('And my ' + weapon);
16+
17+
return 'axe';
18+
})
19+
.then(function(weapon) {
20+
alert('As well as my ' + weapon);
21+
})
22+
23+
defer.resolve('sword');
2124

22-
scope.myFunc = function() {
23-
console.log('myfunct Fired');
24-
};
25-
}
26-
};
2725
});

0 commit comments

Comments
 (0)