一个页面多个ng-app注意事项
Posted 辣牛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个页面多个ng-app注意事项相关的知识,希望对你有一定的参考价值。
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>
以上是关于一个页面多个ng-app注意事项的主要内容,如果未能解决你的问题,请参考以下文章