-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-communication-jsInherit.html
More file actions
55 lines (54 loc) · 2.12 KB
/
angular-communication-jsInherit.html
File metadata and controls
55 lines (54 loc) · 2.12 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>angular-communication-jsInherit</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="app">
<h2>基本类型</h2>
<div ng-controller="ParentController">
<p>Location: {{location}}</p>
<button ng-click="move('ShangHai')">Move</button>
<div ng-controller="ChildController">
<p>Location: {{location}}</p>
<button ng-click="sell('Beijing')">Sell</button>
</div>
</div>
<h2>引用类型</h2>
<div ng-controller="PController">
<p>Location: {{vm.location}}</p>
<button ng-click="move('ShangHai')">Move</button>
<div ng-controller="CController">
<p>Location: {{vm.location}}</p>
<button ng-click="sell('Beijing')">Sell</button>
</div>
</div>
<script>
var app = angular.module('app', []);
app.controller('ParentController', ['$scope', function($scope){
$scope.location = "Guangzhou";
$scope.move = function(newLocation) {
$scope.location = newLocation;
};
}]);
app.controller('ChildController', ['$scope', function($scope){
$scope.sell = function(newLocation) {
$scope.location = newLocation;
};
}]);
app.controller('PController', ['$scope', function($scope){
$scope.vm = {};
$scope.vm.location = "Shenzhen";
$scope.move = function(newLocation) {
$scope.vm.location = newLocation;
};
}]);
app.controller('CController', ['$scope', function($scope){
$scope.sell = function(newLocation) {
$scope.vm.location = newLocation;
};
}]);
</script>
</body>
</html>