ng-app directive is used to define AngularJS application. We can use this to auto-bootstrap an AngularJS application. It designates the root element of AngularJS application and generally kept near <body> or <html> tag. We can define any number of ng-app directive inside the HTML document but only one AngularJS application can be bootstrapped automatically (auto-bootstrapped) the other applications needs to be bootstrapped manually.

Example:

  1. <div ng-app="myApp" ng-controller="myCtrl">
  2. First Name : <input type="text" ng-model="firstName"> <br />
  3. Middle Name: <input type="text" ng-model="middleName"><br />
  4. Last Name : <input type="text" ng-model="lastName"><br>
  5. Full Name: {{firstName + " " + middleName + " " + lastName }}
  6. </div>
Complete HTML Code:
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8" />
  6. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js">
  7. </script>
  8. </head>
  9. <body>
  10. <p>Please enter you details :</p>
  11. <div ng-app="myApp" ng-controller="myCtrl">
  12. First Name : <input type="text" ng-model="firstName"> <br />
  13. Middle Name: <input type="text" ng-model="middleName"><br />
  14. Last Name : <input type="text" ng-model="lastName"><br>
  15. Full Name: {{firstName + " " + middleName + " " + lastName }}
  16. </div>
  17. <script>
  18. var app = angular.module('myApp', []);
  19. app.controller('myCtrl', function ($scope) {
  20. $scope.firstName = "Banketeshvar";
  21. $scope.lastName = "Narayan";
  22. $scope.middleName = "";
  23. });
  24. </script>
  25. </body>
  26. </html>

Browser Display: