例如ng-app="app",如果angular.module("app",[]);中的名字不定义为"app"的话会报错。
怪我咯2017-05-15 17:09:57
ng-app is the entrance to the entire angular application. It will find the corresponding angular module according to the name specified by ng-app. If it is inconsistent, the corresponding module cannot be found for initialization. Therefore, the root module name of the application must be consistent with the name specified by ng-app
大家讲道理2017-05-15 17:09:57
ng-app is the entrance to the entire application, so it must be consistent with the module name of the entrance. An application can only have one and only ng-app
習慣沉默2017-05-15 17:09:57
In an angular application, there can be multiple angular.modules. There should be one and only one angular.module whose name is consistent with the value of ng-app, otherwise it will be meaningless.
angular.module('M1',[]);
angular.module('M2',[]);
......
angular.module('Mn',[]);
angular.module('app',['M1','M2',...,'Mn']);
M1, M2,...,Mn may be different business modules, which can be used as an angular.module alone, and finally all are mounted under the app
module.
----------------------------------Separating line---------- ---------------------------------------
The above is automatically loaded. If you use manual loading, there is no name limit or quantity limit. app
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<body>
<p id="app1">
<p ng-controller="myCtrl">
{{ hello }}
</p>
</p>
<p id="app2">
<p ng-controller="myCtrl">
{{ hello }}
</p>
</p>
<script type="text/javascript">
var app1 = angular.module("test1",[]);
app1.controller("myCtrl",function($scope){
$scope.hello = "a Angular app";
});
var app2 = angular.module("test2",[]);
app2.controller("myCtrl",function($scope){
$scope.hello = " another Angular app";
});
angular.bootstrap(document.getElementById("app1"),['test1']);
angular.bootstrap(document.getElementById("app2"),['test2']);
</script>
</body>
</html>
Rendering
directive. ng-app