AngularJS Scope 2 > 퍼블리싱강좌

퍼블리싱강좌

AngularJS Scope 2 정보

AngularJS AngularJS Scope 2

본문

AngularJS Scope

범위는 HTML (보기)와 JavaScript (컨트롤러) 간의 바인딩 부분입니다.

범위는 사용 가능한 속성 및 메서드가있는 객체입니다.

범위는 뷰와 컨트롤러 모두에서 사용할 수 있습니다.


범위 이해하기
AngularJS 응용 프로그램을 다음으로 구성한다고 간주 할 경우 :

보기, HTML입니다.
현재보기에 사용할 수있는 데이터 인 모델
Controller : 데이터를 변경 / 제거 / 제어하는 ​​JavaScript 함수입니다.
그런 다음 범위가 모델입니다.

범위는 뷰와 컨트롤러에서 사용할 수있는 속성 및 메서드가있는 JavaScript 객체입니다.


뷰를 변경하면 모델과 컨트롤러가 업데이트됩니다.

<div ng-app="myApp" ng-controller="myCtrl">

<input ng-model="name">

<h1>My name is {{name}}</h1>

</div>

<script>
var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope) {
    $scope.name = "John Doe";
});
</script>


소스
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

<input ng-model="name">

<h1>My name is {{name}}</h1>

</div>

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

<p>When you change the name in the input field, the changes will affect the model, and it will also affect the name property in the controller.</p>

</body>
</html>
추천
0
  • 복사

댓글 0개

© SIRSOFT
현재 페이지 제일 처음으로