Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

AngularJS ng-app Directive

AngularJS ng-app Instruction

AngularJS Reference Manual AngularJS Reference Manual


AngularJS Examples

Make the body element the root element of the AngularJS application:

<

body

ng-app=

""

<

p

My first expression:

{{ 5 + 5 }}

<

/p

<

/body

Try 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 +

" "

<

/div

<

script

var

app = angular.module(

"myApp"

, []);

app.controller(

"myCtrl"

,

function

($scope) {

    $scope.firstName =

"John"

;

    $scope.lastName =

"Doe"

;

});

<

/script

Try it »


AngularJS Reference Manual AngularJS Reference Manual