Menu ▼


ng-app directive in AngularJS

In AngularJS, ng-app directive is used as root element (like <html>, <body> tags) of the application, when ng-app directive is used then the application will be recognized as AngularJS application.

When ng-app directive is used then it auto bootstrap an AngularJS application and only one AngularJS application can be auto-bootstrapped in a webpage. The first ng-app directive found in the page will be treated as root element and bootstrapped automatically. If an HTML document contains multiple multiple AngularJS(ng-app) applications then the remaining have to be bootstrapped manually.

Note:
One AngularJS application can not be placed inside another application, i.e. AngularJS applications cannot be nested within each other.

Syntax:
<body ng-app="">
Using directive by giving a name
<body ng-app="sampleApp">

We will discuss more about using ng-app directive by giving a name in coming articles.

Example:
Multiplicaiton of 2 X 10 = {{ 2*10 }}

Soruce code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>
</head>
<body ng-app="">
Multiplicaiton of 2 X 10 = {{ 2*10 }}
</body>
</html>





comments powered by Disqus


Search dotnetlearners.com