ANGULARJS Study Notes (1)--ng-app

Source: Internet
Author: User

Known:

The ng-app instruction is used to tell the AngularJS application that this element is the root element.

All AngularJS applications must have a single root element.

only one ng-app instruction is allowed in the HTML document , and if there are multiple ng-app instructions, only the first one will be used, and the first Ng-app will be loaded automatically by one page.

Using Ng-app to declare angular boundaries, you can use the Ng-app directive to tell angular which piece of the page should be managed, either the entire HTML or a div

A ng-app can have multiple controllers

The scope of the $scope is limited to each controller

Here's the problem:

I just want more ng-app, although I do not know what is the use???

Here are some examples:

<!DOCTYPE HTML><HTML><Scriptsrc= "Http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js"></Script><Body><DivID= "App1"Ng-app= "App1"><spanNg-controller= "Myctrl"Ng-init= "Firstname= ' John '; lastname= ' Doedoe '">{{firstName + "" + LastName}}</span><BR><spanNg-controller= "Yourctrl">{{secondname + "" + Thirdname}}</span></Div><BR><DivID= "App2"Ng-app= "App2"Ng-controller= "Yourctrl">{{secondname + "" + Thirdname}}</Div><Script>varapp=Angular.module ("App1", []); App.controller ("Myctrl", function($scope) {//$scope. LastName = "Doe";}); App.controller ("Yourctrl", function($scope) {$scope. Secondname= "Xiaomi 1"; $scope. Thirdname= "Rice 1";});varApp1=Angular.module ('App2', []); App1.controller ("Yourctrl", function($scope) {$scope. Secondname= "Xiaomi 4"; $scope. Thirdname= "Xiaomi 5";});//The default load is App1, which displays the startup app2 by the following code, but must be written after the APP2 declarationAngular.bootstrap (document.getElementById ("app2"), ['App2']);</Script></Body></HTML>

ANGULARJS Study Notes (1)--ng-app

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.