Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

AngularJS ng-app Directive

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The ng-app Directive in AngularJS is used to define the root element of an AngularJS application. This directive automatically initializes the AngularJS application on page load. It can be used to load various modules in AngularJS applications. The ng-app directive declares only once in the HTML document. In case if it is declared more than once then the first ng-app directive appears will be used.

Syntax:

<element ng-app="dataModule"> 
    Contents... 
</element>

Parameter value:

  • dataModule: It specifies the name of the module that is to be loaded in the application. It is an optional parameter.

Example 1: This example implements the ng-app Directive to define a default AngularJS application.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>AngularJS ng-app Directive</title>
    <script src=
    </script>
</head>
  
<body style="text-align:center">
    <h1 style="color: green">GeeksforGeeks</h1>
    <h3>ng-app directive</h3>
    <div ng-app="" ng-init="name='GeeksforGeeks'">
        <p>{{ name }} is the portal for geeks.</p>
    </div>
</body>
</html>

Output:

 

Example 2: This example implements the ng-app Directive to define a default AngularJS application. 

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>
        AngularJS ng-app Directive
    </title>
    <script src=
    </script>
</head>
  
<body ng-app="" style="text-align: center">
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
    <h2>ng-app Directive</h2>
    <div>
        <p>Name:
            <input type="text" ng-model="name">
        </p>
        <p>You entered:
            <span ng-bind="name"></span>
        </p>
    </div>
</body>
</html>

Output:

 


My Personal Notes arrow_drop_up
Last Updated : 01 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials