AngularJS ng-app directive
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>Running results:
My first expression: 10
Definition and usage
The ng-app directive is used to tell AngularJS to apply the current element as the root element.
All AngularJS applications must require a root element.
Only one ng-app directive is allowed in the HTML document. If there are multiple ng-app directives, only the first one will be used.
grammar
<element ng-app="modulename">... Content on the ng-app root element can contain AngularJS code...</element>
All HTML elements support this directive.
Parameter value
| value | describe |
|---|---|
| modulename | Optional. Specifies the name of the loaded application module. |
AngularJS instance
Execute 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>Running effect:
John Doe
The above is the information sorting out the AngularJS ng-app directive, and will be added later.