-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path02-angular.html
More file actions
45 lines (35 loc) · 957 Bytes
/
02-angular.html
File metadata and controls
45 lines (35 loc) · 957 Bytes
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
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div ng-controller="Aaa">
<h1> {{ name }} </h1>
<div ng-controller="Bbb">
<h1> {{ name }} </h1>
<h1> {{ age }} </h1>
</div>
</div>
<script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var m1 = angular.module("myApp",[]);
m1.controller('Aaa',function($scope,$rootScope){
// 服务 $scope: 局部作用域
// 服务 $rootScope: 全局作用域
$scope.name = 'hello';
// $scope.age = 20;
// 之后找父级的age数据
$rootScope.age = 22;
// 最后找全局的age
})
m1.controller('Bbb',function($scope){
// 服务 $scope: 局部作用域
$scope.name = 'hi';
// $scope.age = 18;
// 如果是嵌套关系:首先找Bbb中自身的局部变量
})
</script>
</body>
</html>