Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

AngularJS | ng-app Directive

  • Last Updated : 28 Mar, 2019

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

Syntax:

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

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




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

Output:
ng-app

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




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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!