Latest web development tutorials

AngularJS ng-app directive

AngularJS Reference Manual AngularJS Reference Manual


AngularJS examples

Let the body element is called the root element AngularJS application:

<Body ng-app = "" >

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

</ Body>

try it"

Definition and Usage

ng-app directive is used to tell current AngularJS application of this element is the root element.

All AngularJS applications must be a root element.

HTML document allows only one ng-app directive, if there are multiple ng-app directive, only the first one will be used.


grammar

<Element ng-app = "modulename ">
...
Ng-app content in the root element may contain AngularJS Code
...
</ Element>

All HTML elements support the instruction.


Parameter Value

value description
modulename Optional. Specifies the name of the application load module.

AngularJS examples

Execution of the application modules

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

try it"

AngularJS Reference Manual AngularJS Reference Manual