AngularJS | ng-app Directive

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.



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
ng-app

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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:
ngapp



My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.