English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

AngularJS ng-app directive

AngularJS Reference Manual

!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js></script>
</head>
<body ng-app="">
<p>My first expression: {{ 5 + 5 }}</p>
</body>
</html>
Test and See ‹/›

Definition and Usage

ng-app Directives are used to tell AngularJS applications that the current element is the root element.

All AngularJS applications must have a root element.

Only one root element is allowed in the HTML document. ng-app directives, if there are multiple ng-app If there are multiple directives, only the first one will be used.

Syntax

<element ng-app="modulename">
...
 in ng-app 
   The content of the root element can include AngularJS code
...
</element>
All HTML elements support this directive.

Parameter Value

ValueDescription
modulenameOptional. Specifies the name of the module that loads the application.
!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/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>
Test and See ‹/›

AngularJS Reference Manual