AngularJS Ng-app Auto-load and attribute values

Source: Internet
Author: User


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:

  • strictDi-Disable automatic function annotation for the application. This was meant toassist in finding bugs which break minified code. Defaults to false .


element should correspond to the ID of the root ng-app,

modulesModule an array group


AngularJS Ng-app Auto-load and attribute values

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.