본문 바로가기
IT/JavaScript와 Framework

AngularJS - routeProvider와 urlRouterProvider 차이 $rootScope.on 에 대한 써머리들

by 골든크랩 2022. 4. 29.
728x90
반응형

이것 저것 잡다한 것들 정리

 

$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

728x90
반응형

댓글