-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmvc.html
More file actions
40 lines (37 loc) · 976 Bytes
/
mvc.html
File metadata and controls
40 lines (37 loc) · 976 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
<!DOCTYPE html>
<html ng-app="appModule">
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!--我们的控制器-->
<div ng-controller="appCtrl">
{{name}}
</div>
<div ng-controller="homeCtrl">
{{name}}
{{age}}
<div ng-controller="appCtrl">
{{name}}
{{age}}
</div>
</div>
</body>
</html>
<script src="angular.js"></script>
<script>
//这是我们的模块
var app=angular.module('appModule',[]);//新生成的模块;这里app就是MVC的M(model)
//这是控制器的定义,controller是和上面ng-controller对应的;
app.controller('appCtrl',function($rootScope,$scope){
//$scope就是我们的模型了
console.log($scope);//{}
$scope.name="broszhu";//给模型定义名称属性;
$rootScope.root='root';//根作用域
});
app.controller('homeCtrl',function($scope){
$scope.name="zhuzhu";
$scope.age="26";
})
</script>