|
1 | 1 | // Define an App
|
2 | 2 | var app = angular.module('app', []);
|
3 | 3 |
|
4 |
| -app.controller('AppCtrl', function($scope, $q) { |
5 |
| - |
6 |
| - var defer = $q.defer(); |
7 |
| - |
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 |
| - }) |
| 4 | +app.directive('country', function() { |
| 5 | + return { |
| 6 | + restrict: 'E', |
| 7 | + controller: function() { |
| 8 | + this.makeAnnouncement = function(message) { |
| 9 | + console.log('Country says: ' + message); |
| 10 | + } |
| 11 | + } |
| 12 | + }; |
| 13 | +}); |
22 | 14 |
|
23 |
| - defer.resolve('sword'); |
| 15 | +app.directive('state', function() { |
| 16 | + return { |
| 17 | + restrict: 'E', |
| 18 | + require: '^country', |
| 19 | + controller: function() { |
| 20 | + this.makeLaw = function(law) { |
| 21 | + console.log('Law: ' + law); |
| 22 | + } |
| 23 | + }, |
| 24 | + link: function(scope, element, attrs, countryCtrl) {} |
| 25 | + }; |
| 26 | +}); |
24 | 27 |
|
| 28 | +app.directive('city', function() { |
| 29 | + return { |
| 30 | + restrict: 'E', |
| 31 | + require: ['^country', '^state'], |
| 32 | + link: function(scope, element, attrs, ctrls) { |
| 33 | + ctrls[0].makeAnnouncement('from city'); |
| 34 | + ctrls[1].makeLaw('Jump higher'); |
| 35 | + } |
| 36 | + }; |
25 | 37 | });
|
0 commit comments