기본 콘텐츠로 건너뛰기

angular js scope와 rootscope 의 차이

angular js scope와 rootscope 의 차이

inflearn 의 Start Google Angular.js 앵귤러 과정 강좌를 보고 정리한 내용입니다.

https://www.inflearn.com/course/angular-js

angular js scope와 rootscope 의 차이

angularjs scope란?

scope 는 controller를 적용한 태그 내에서 사용할 변수나 함수를 저장해 놓을 수 있는 객체입니다.

angularjs rootscope란?

rootScope 는 문서 전체에서 사용할 변수나 함수를 저장해 놓는 객체입니다.

$rootScope 를 지정한 app.run() 함수는 angularjs module 객체가 생성되면 실행되는 함수입니다.

따라서 app module 객체가 생성되면 문서 전체에서 사용할 수 있는 data1, data2 변수가 생성됩니다.

$rootScope 를 지정한 run 함수는 angularjs module 객체가 생성되면 실행되는 함수입니다.

따라서 app 모듈 객체가 생성되면 data1 = 100, data2 = 200이 할당됩니다.

먼저 선언된 $rootScope 보다 뒤에 선언된 controller의 data1 = 1000 에 따라 최종적으로 data1 에는 1000이 할당됩니다.

controller 에서 data2에는 값을 재할당하지 않았으므로,

$rootScope 에서 설정한 200이 할당되어 있습니다.

controller 를 여러개 만들고, controller 마다 사용하는 data 변수를 다르게 지정해줄 수 있습니다.

angularjs 관련 다른 글 ▼

angular js 예제, 강의 정리 (module, controller, service, factory)

angularjs ng-model 이란?

angular js scope와 rootscope 의 차이

angularjs table 예제

from http://minimilab.tistory.com/49 by ccl(A) rewrite - 2020-03-06 23:20:57

댓글

이 블로그의 인기 게시물

angular4 custom RouteReuseStrategy

angular4 custom RouteReuseStrategy import { RouteReuseStrategy, ActivatedRouteSnapshot, DetachedRouteHandle } from "@angular/router"; /* 호출 관계 테스트 1. /proc 열기 shouldReuseRoute. future: /, curr : / retrieve : / retrieve : / retrieve : /proc/ retrieve : /proc/ shouldAttach : / shouldAttach : /proc/ 2. /mem 이동 shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /proc/, curr : /mem/ retrieve : /mem/ retrieve : /mem/ shouldDetach : /proc/ store : /proc/ shouldAttach : /mem/ 3. /net 이동 shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /, curr : / shouldReuseRoute. future: /mem/, curr : /net/ retrieve : /net/ retrieve : /net/ shouldDetach : /mem/ store : /mem/ shouldAttach : /net/ 4. /mem 로 다시...

[Debugging] AngularJS2 - Can't bind to 'ngModel' since it isn't a...

[Debugging] AngularJS2 - Can't bind to 'ngModel' since it isn't a... - 좋아요 하이 .. !! Angular2 로 개발을 하다가 아래와 같은 에러를 만났다. 흠 .. 이게 뭘까 열심히 구글링을 해봤다. 간단한 내용이다. 모듈을 추가해주기만 하면 된다. app.module.ts를 열어보자. 여기에다가 FormsModule 과 ReactiveFormsModule을 추가해주면 문제가 해결된다 ! 다들 즐거운 코딩하자. from http://devkingdom.tistory.com/106 by ccl(A) rewrite - 2020-03-18 00:54:15