AngularJS ng-appDirective

AngularJS 参考手册AngularJS Reference Manual


AngularJS Example

Make the body element the root element of an AngularJS application:

<body ng-app="">

<p>My first expression:{{ 5 + 5 }}</p>

</body>

Try it Yourself »

Definition and Usage

ng-appThe directive is used to tell the AngularJS application that the current element is the root element.

All AngularJS applications must have a root element.

In an HTML document, only oneng-appdirective is allowed; if there are multipleng-appdirectives, only the first one will be used.


Syntax

<element ng-app="modulename">
...
Content within the ng-app root element can contain AngularJS code
...
</element>

All HTML elements support this directive.


Parameter Value

Value Description
modulename Optional. Specifies the name of the module to load.

AngularJS Example

Run the module in the application

<div ng-app="myApp" ng-controller="myCtrl">
    {{ firstName + " " + lastName }}
</div>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
});
</script>

Try it Yourself »

AngularJS 参考手册AngularJS Reference Manual

Other Extensions