Sunday, February 15, 2015

ng-app directive

The ng-app directive is used to initialize / bootstrap an AngularJS application in a HTML page, we should declare the ng-app directive in the HTML, Body or DIV tag based on where we plan to use AngularJS directives in the page. Without adding the ng-app directive the other AngularJS directives / expressions will not work.

There can be only one ng-app defined in a page, to have multiple applications in a single HTML page we should manually bootstrap the page using angular.bootstrap.

For a simple application we can just specify the ng-app directive in the HTML, Body or div tags without any specific names as follows.


The following is a simple example using ng-app 
<html ng-app>
<head>
    <meta charset="utf-8" />
    <title>AngularJS - Basic</title>
    <script src="angular.min.js"></script>
</head>
<body>
<p>Simple Expression (1+2) = {{1 + 2}}</p>
</body>

</html>

Output



To define complex applications with controllers and modules we will have to specify an application name to bind with the modules and controllers.

<html ng-app="BasicApp">
<body>
<div ng-controller="BasicAppController">
</div>
</body>
</html>


Search Flipkart Products:
Flipkart.com

No comments: