-
Notifications
You must be signed in to change notification settings - Fork 0
/
directiveCommunication.html
71 lines (63 loc) · 1.54 KB
/
directiveCommunication.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//cdn.bootcss.com/angular.js/1.5.0/angular.js"></script>
<title></title>
</head>
<body ng-app="myapp">
<superman streng>我!就是力量的化身</superman>
<superman streng speed>力量+敏捷</superman>
<superman streng speed light>力量+敏捷+光</superman>
<script type="text/javascript">
var app = angular.module('myapp',[]);
app.directive('superman',function(){
return {
scope: {},
restrict: 'AE',
controller: function( $scope ){
$scope.abilities = [];
this.addStreng = function(){
$scope.abilities.push('strength')
};
this.speed = function(){
$scope.abilities.push('speed')
};
this.light = function(){
$scope.abilities.push('light')
}
},
link: function(scope,element,attrs){
element.bind('mouseenter',function(){
console.log(scope.abilities)
})
}
}
})
app.directive('streng',function(){
return{
require:'^superman',
link:function(scope,element,attrs,supermanCtrl) {
supermanCtrl.addStreng();
}
}
})
app.directive('speed',function(){
return{
require:'^superman',
link:function(scope,element,attrs,supermanCtrl) {
supermanCtrl.speed();
}
}
})
app.directive('light',function(){
return{
require:'^superman',
link:function(scope,element,attrs,supermanCtrl) {
supermanCtrl.light();
}
}
})
</script>
</body>
</html>