posted by 네코냥이 2014. 9. 25. 10:15

[angular] $broadcast, $emit, $on AngularJS 2014/09/12 17:26


출처: http://blog.naver.com/suy6107/220119971824


$broadcast

==> 부모 컨트롤러에서 자식 컨트롤러로 이벤트를 방송

$emit

==> 자식 컨트롤러에서 부모 컨트롤러로 이벤트 방송

$on

==> 방송한 이벤트를 받는다.

<부모>

$scope.$broadcast("parentToChildEvent", args); //자식에게 방송

<자식>

$scope.$on("parentToChildEvent", function(event, args) {

//이벤트 처리

});

<자식>

$scope.$emit("childToParentEvent", args); //부모에게 방송

<부모>

$scope.$on("childToParentEvent", function(event, args) {

//이벤트 처리

});