AngularJS- ng-appDirektive


Beispiel

Lassen Sie das Body-Element zum Root-Element für die AngularJS-Anwendung werden:

<body ng-app="">

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

</body>

Definition und Verwendung

Die ng-appDirektive teilt AngularJS mit, dass dies das Wurzelelement der AngularJS-Anwendung ist.

Alle AngularJS-Anwendungen müssen ein Root-Element haben.

Sie können nur eine ng-appDirektive in Ihrem HTML-Dokument haben. Wenn mehr als eine ng-appAnweisung vorkommt, wird das erste Vorkommen verwendet.


Syntax

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

Unterstützt von allen HTML-Elementen.


Parameterwerte

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

Beispiel

Laden Sie ein Modul, das in der Anwendung ausgeführt werden soll

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