1.一个页面会自动加载第一个ng-app
2.如果想启动其它ng-app,需要通过下列代码的红色部分来启动,此时一共启动了2个ng-app
3.特别注意:代码红色部分一定要放在最后,比如,不能放在蓝色代码之前,否则会出错
4.一个ng-app可以有多个controller
5.$scope的范围局限于每一个controller中
<!DOCTYPE html>
<html>
<script src="http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js"></script>
<body>
<div id="app1" ng-app="myApp">
<span ng-controller="myCtrl">{{ firstName + " " + lastName }}</span>
<br>
<span ng-controller="yourCtrl">{{ secondName + " " + thirdName + (1 + 2) }}</span>
</div>
<br>
<div id="app2" ng-app="yourApp" ng-controller="yourCtrl">
{{1 + 2}}
{{ secondName + " " + thirdName }}
</div>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});
app.controller("yourCtrl", function($scope) {
$scope.secondName = "xiaoming";
$scope.thirdName = "daming";
});
var app1 = angular.module(‘yourApp‘, []);
app1.controller("yourCtrl", function($scope) {
$scope.secondName = "yitianjian";
$scope.thirdName = "tulongdao";
});
angular.bootstrap(document.getElementById("app2"), [‘yourApp‘]);
</script>
</body>
</html>