-
Notifications
You must be signed in to change notification settings - Fork 5
/
28.directive_communication.html
89 lines (70 loc) · 1.65 KB
/
28.directive_communication.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Directive communication » Angular</title>
</head>
<body>
<div ng-app="app">
<div ng-controller="controller">
<country>
<state><city></city></state>
</country>
</div>
</div>
<script src="src/angular.1.3.min.js"></script>
<script>
var app = angular.module("app", []);
app.controller("controller", function($scope){
$scope.countryList = [
{ name: "Bangladesh", code: "BD" },
{ name: "United states", code: "USA" },
{ name: "Russia", code: "RU" }
];
$scope.cityList = {
"BD" : ["Dhaka", "CTG", "Rajshahi"],
"USA" : ["NY", "PA", "CA"],
"RU" : ["Moscow", "RQ", "SQ"]
};
$scope.state = {
"Dhaka" : ["Uttara", "Banani", "Mirpur"],
"NY" : ["NA", "NB", "NC"],
"Moscow" : ["MA", "MB", "MC"]
};
});
app.directive("country", function(){
return {
restrict: "E",
controller: function(){
this.makeAnnouncement = function(msg){
alert("Country says " + msg);
}
}
}
});
app.directive("state", function(){
return {
restrict: "E",
controller: function(){
this.makeLaw = function(msg){
alert("State says: "+msg);
}
},
require: "^country",
link: function($scope, element, attr, countryCtrl){
}
}
});
app.directive("city", function(){
return {
restrict: "E",
require: ['^country', '^state'],
link: function($scope, element, attr, ctrls){
ctrls[0].makeAnnouncement("City overwrites country!");
ctrls[1].makeLaw("City overwrites country!");
}
}
});
</script>
</body>
</html>