AngularJS ng-app지시문


예시

body 요소를 AngularJS 애플리케이션의 루트 요소로 설정합니다.

<body ng-app="">

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

</body>

정의 및 사용

ng-app지시문은 이것이 AngularJS 애플리케이션의 루트 요소임을 AngularJS에 알려줍니다.

모든 AngularJS 애플리케이션에는 루트 요소가 있어야 합니다.

ng-appHTML 문서에는 지시문 이 하나만 있을 수 있습니다 . 둘 이상의 ng-app지시문이 나타나면 첫 번째 표시가 사용됩니다.


통사론

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

모든 HTML 요소에서 지원됩니다.


매개변수 값

Value Description
modulename Optional. Specifies the name of a module to load with 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>