이것 저것 잡다한 것들 정리
$scope.on('event'); will listen to $scope.$broadcast('event') & $rootScope.$broadcast('event')
$rootScope.on('event'); will listen to $rootScope.$broadcast('event') & $rootScope.$emit('event')
$scope.on(); will be destroyed automatically when the controller loses it representation in view or component (getting destroyed).
You need to destroy $rootScope.$on() manually.
Example of how to destroy $rootScope.on():
//bind event
var registerScope = $rootScope.$on('someEvent', function(event) {
console.log("fired");
});
// auto clean up `$rootScope` listener when controller getting destroy
// listeners will be destroyed by calling the returned function like registerScope();
$scope.$on('$destroy', registerScope);
The difference between $emit & $broadcast is:
$rootScope.$emit() events only triggers $rootScope.$on() events.
$rootScope.$broadcast() will trigger $rootScope.$on() & $scope.on()events (pretty much everthing hear this event).
$scope.$emit() will trigger all $scope.$on, all its parents (scopes in parent controllers) and $rootScope.$on().
$scope.$broadcast will only trigger $scope and its children (scopes in child controllers).
■AngularJS, 전역 범위($rootScope)에 이벤트 핸들러 등록하기
- AngularJS의 run() 메써드에 전달한 함수는 앱의 최초 부트스트래핑 과정에서 실행된다. 마치 Java의 main() 함수와 유사한 기능을 한다.
run() 메써드의 실행 시점은 config()와 controller() 사이이다. 앱의 전체 스코프에 필요한 이벤트 핸들러 등을 작성할 때 유용하다.
https://jsonobject.tistory.com/268
routeProvider 와 urlRouterProvider
https://jeonghwan-kim.github.io/ui-route%EB%A1%9C-%EB%9D%BC%EC%9A%B0%ED%8C%85-%EC%9D%B8%EC%A6%9D-%EA%B5%AC%ED%98%84/
https://code-examples.net/ko/q/14edf84
routeProvider -> urlRouterProvider 변경하는 코드가 있는듯
https://github.com/angular-ui/ui-router/issues/26
Difference between $routeProvider and $urlRouterProvider
'IT > JavaScript와 Framework' 카테고리의 다른 글
AngularJS 를 이용한 대규모 프로젝트 구축시 프로그램 구조 만드는 방법 (0) | 2022.05.02 |
---|---|
Angualar에서 ng-conller as 문법에 대한 설명된 곳... (0) | 2022.05.02 |
AngualJS 라우팅과 localStorage 등등 잡탕 (0) | 2022.04.27 |
eclipse - AngualrJS 실습1 (0) | 2022.04.21 |
AngularJS 서비스 생성 API provider, factory, service (0) | 2022.04.18 |
댓글