<!DOCTYPE HTML>
<html ng-app>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script>//MVC //function Aaa($scope){
// $scope.name = 'hello';//Model,$scope是对象name是对象的属性,scope是作用域范围是ng-controller="Aaa"标签范围。
// $scope.age = '20';
//}
function Aaa($scope,$rootScope){//$rootScope是作用域是全局作用域范围是整个页面,
$scope.name = 'hello';
$scope.age = '';//局部作用域覆盖全局作用域
$rootScope.age = '';
}
function Bbb($scope){
$scope.name = 'hi';
$scope.age = '';
} </script>
</head> <body>
<div ng-controller="Aaa"> //Control,ng-controller是作用域,范围是div范围。
<p>{{name}}</p> //View <div ng-controller="Bbb">
<p>{{name}}</p>
<p>{{age}}</p>
</div> </div> </body>
</html>
<!DOCTYPE HTML>
<html ng-app>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script> //传统函数的定义与调用
function show(n){
}
show(); function Aaa($scope,$rootScope){//传入了局部作用域的对象和全局作用域的对象
alert();
} </script>
</head> <body>
<div ng-controller="Aaa"> //写了这个就会执行Aaa函数,
</div> </body>
</html>