AngularJS ng-app
Directive
AngularJS Example
Make the body element the root element of an AngularJS application:
<body ng-app=""><p>My first expression: {{ 5 + 5 }}</p></body>
Definition and Usage
The ng-app directive is used to tell AngularJS that this element is the root element of the application.
Every AngularJS application must have a root element.
Only one ng-app
directive is allowed in an HTML document. If multiple ng-app
directives are present, only the first one will be used.
Syntax
This directive is supported by all HTML elements.
Parameter Values
Value | Description |
---|---|
modulename | Optional. Specifies the name of the application module to load. |
AngularJS Example
Execute 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>