-
Notifications
You must be signed in to change notification settings - Fork 5
/
directive2directive.js
56 lines (49 loc) · 1.16 KB
/
directive2directive.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var app = angular.module('superApp', []);
app.directive('superhero', function() {
return {
restrict: 'E',
scope: {},
controller: function($scope) {
$scope.abilities = [];
this.addStrength = function() {
$scope.abilities.push('strength');
}
this.addSpeed = function() {
$scope.abilities.push('speed');
}
this.addFlight = function() {
$scope.abilities.push('flight');
}
},
link: function(scope, element) {
element.addClass('button');
element.bind('mouseenter', function() {
console.log(scope.abilities)
});
}
}
});
app.directive('strength', function() {
return {
require: "superhero",
link: function(scope, element, attrs, superheroCtrl) {
superheroCtrl.addStrength();
}
}
})
app.directive('speed', function() {
return {
require: "superhero",
link: function(scope, element, attrs, superheroCtrl) {
superheroCtrl.addSpeed();
}
}
})
app.directive('flight', function() {
return {
require: "superhero",
link: function(scope, element, attrs, superheroCtrl) {
superheroCtrl.addFlight();
}
}
})