Angularjs Ng-app Instruction Example detailed _angularjs

Source: Internet
Author: User


Angularjs Ng-app Instruction



Angularjs instance



Let the body element be called the root element of the ANGULARJS application:


<! DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<script src = "http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"> </ script>
</ head>
<body ng-app = "">

<p> My first expression: {{5 + 5}} </ p>

</ body>
</ html>


Run Result:



My first expression: 10



Definitions and usage



The ng-app instruction is used to tell the ANGULARJS application that the current element is the root element.



All ANGULARJS applications must have a root element.



Only one ng-app instruction is allowed in an HTML document, and if there are multiple Ng-app directives, only the first one will be used.



Grammar


<element ng-app= "ModuleName" > ...
 The content on the Ng-app root element can contain Angularjs code
...
</element>


All HTML elements support this directive.



Parameter values





value Description
ModuleName Optional. Specifies the name of the load application module.





Angularjs instance



Executing modules in the application


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
{{ firstName + " " + lastName }}
</div>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.firstName = "John";
  $scope.lastName = "Doe";
});
</script>

</body>
</html>


Operation Effect:



John Doe



Above is the Angularjs Ng-app instructions of the data collation, follow-up continue to add.


Related Article

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.