AngularJS ng-app Instruction
AngularJS Examples
Make the body element the root element of the AngularJS application:
<
body
ng-app=
""
<
pMy first expression:
{{ 5 + 5 }}
<
/p
<
/bodyTry it »
Definition and Usage
ng-app The directive tells the AngularJS application that this element is the root element.
Every AngularJS application must have a root element.
Only one is allowed in an HTML document ng-app directive; if there are multiple ng-app directives, only the first one will be used.
Syntax
<
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 | Description |
|---|---|
| modulename | Optional. Specifies the name of the application module to load. |
AngularJS Examples
Executes the module in the application
<
div
ng-app=
"myApp"
ng-controller=
"myCtrl"{{ firstName +
" "
- lastName }}
<
/div
<
script
varapp = angular.module(
"myApp"
, []);
app.controller(
"myCtrl"
,
function
($scope) {
$scope.firstName =
"John"
;
$scope.lastName =
"Doe"
;
});
<
/script
Try it »
AngularJS Reference Manual