The ng-app instruction is used to tell the AngularJS application that this element is the root element, and all AngularJS applications must have a root element.
Using Ng-app to mark a DOM node, the application is automatically booted (automatically initialized) when the page is loaded.
Ng-app can take a property value, you can specify the name of the Load application module, ng-app= the "module name".
However, only one instruction is allowed in the HTML document ng-app , and if there are multiple ng-app instructions, only the first one will be used.
So if you want to implement automatic loading, then you can't have ng-app with attribute values, that is, you cannot specify the load application module name.
Correct wording
<body ng-app> <div ><p> {5 + 5}}</p> </div> <div ><p> {ten +}}< /p> </div></body>
Load only the first block
<body > <div ng-app><p> {{5 + 5}}</p> </div> <div ng-app><p> {{10 + 10 }}</p> </div></body>
The following is an incorrect notation for adding attribute values to Ng-app.
<body ng-app= "myApp" > <div ><p> {{5 + 5}}</p> </div> <div ><p> {10 + 1 0}}</p> </div></body>
<body > <div ng-app= "App1" ><p> {{5 + 5}}</p> </div> <div ng-app= "APP2" ><P&G T {Ten +}}</p> </div></body>
Manual loading of the corresponding Ng-app is required when with attribute values
<body> <div id= "App1" ng-app= "App1" >{{5 + 5}}</div> <div id= "app2" ng-app= "APP2" >{{10 + 1 0}}</div> <script type= "Text/javascript" > var App1 = angular.module ("App1", []); var app2 = angular.module ("App2", []); Angular.bootstrap (document.getElementById ("app2"), [' app2 ']); </script></body>
App1 will automatically load
APP2 need to be manually loaded
Angular.bootstrap (), manual start AngularJS
Document Address Https://docs.angularjs.org/api/ng/function/angular.bootstrap
angular.bootstrap(element, [modules], [config]);
Arguments
| Param |
Type |
Details |
| Element |
DomElement |
DOM element which is the root of angular application. |
| Modules (optional) |
array<string| function| array>= |
An array of modules to load into the application. ea CH item in the array should is the name of a predefined module or a (DI annotated) function that'll be invo Ked by the injector as a config block. see:modules |
| Config (optional) |
Object |
An object for defining configuration options for the application. The following keys are supported:
|
element should correspond to the ID of the root ng-app,
modulesModule an array group
AngularJS Ng-app Auto-load and attribute values