Programming/AngularJS

[AngularJS] (8) scope 객체 | scope, rootScope

Yejii 2021. 11. 21. 16:40

목차

(1) 기본 웹 서비스 개발환경 구축

(2-1) 기본 예제

(2-2) AngularJS 템플릿 만들고 적용하기

(3) 표현식 | {{data}}

(4) 모듈 | angular.module("appName", [])

(5) 지시자 | angular.directive(), ng-app, ng-init, ng-repeat

(6) 모델 | ng-model, ng-show, valid, dirty, touched

(7) Controller

(8) scope 객체 | scope, rootScope

(9) 필터 | uppercase, lowercase, orderBy, currency, date, filter, json, limitTo, number

(10) 서비스 | location, get, timeout, interval, app.service()

 


1. scope 객체

scope 객체는 Controller를 적용한 tag 내에서 사용할 변수나 함수를 저장해 놓을 수 있는 객체이다.

 

> 다양한 type의 변수, 객체, 배열, 함수를 저장해 놓고 tag 내에서 사용

 

 

 

2. rootScope 객체

angular module을 통해 지정한 애플리케이션 전체에서 사용할 변수나 함수를 선언하고 초기화할 수 있다.

 

> 별도의 controller 지정없이 특정 변수를 tag안에서 사용할 수 있다.

 

> $rootScope와 controller의 $scope동일한 변수가 저장되어 있다면, controller에서 정의된 $scope의 값으로 덮어씌워진다.