ng-app

Description

ng-app marks the element as the beginning of the $rootScope.

ng-app modifies the scope of directives.

$rootScope is the root of the scope chain, and all directives under the ng-app in HTML inherit from it.

We can only use ng-app once per document.

Example

In the following you can access the $rootScope via the run method:


<!doctype html>
<html ng-app="myApp">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.js"></script>
</head><!--from w w  w. j  a  v a  2 s  . com-->
<body>
  {{ myProperty }}
  <button ng-click="someAction()">Click to change</button>

  <script>
    angular.module('myApp', [])
    .run(function($rootScope) {
      $rootScope.myProperty = 'A';
      $rootScope.someAction = function() {
        $rootScope.myProperty = 'B';
      };
    });
  </script>

</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Tutorial »




Introduction
Buildin Filters
Buildin Directives