์ด๊ฒ์ ๋ด๊ฐ ์๋ํ ๊ฒ์ ๋๋ค :
$rootScope.$on("$broadcast", function ($event) {
console.log("BROADCAST: " + $event.name);
});
์ด๊ฒ์ (๋ฌธ์๋ฅผ ์ฐพ์ ์ ์์) ๊ตฌํ๋ ์์ ์ด๊ฑฐ๋ ์ค๋ฒํค๋๊ฐ ๋๋ฌด ํฝ๋๊น?
๋ด ์๊ฐ์ $route ์ด๋ฒคํธ ๋ฌธ์(์: $routeChangeSuccess
.
์ด๊ฒ์ ์ค๋ฒํค๋๋ก ์ธํด ๊ทํ๊ฐ ๋งํ๋ฏ์ด ๊ตฌํ๋ ๊ฐ๋ฅ์ฑ์ด ์๋ ๊ฒ์ด ์๋๋๋ค.
๊ทธ๋ฌ๋ ์์ ์ ์ฑ์ ์๋ฆฌ๋ฏธ๋ฅผ ๊ตฌํํ๋ ๊ฒ์ด ๊ฐ๋ฅํ๋ฏ๋ก ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ์์ ์ ์ฑ์ ์๋ฆฌ๋ ๋ฐฉ๋ฒ์ ๋ง๋ค ์ ์์ต๋๋ค.
app.config(function($provide) {
$provide.decorator("$rootScope", function($delegate) {
var Scope = $delegate.constructor;
var origBroadcast = Scope.prototype.$broadcast;
var origEmit = Scope.prototype.$emit;
Scope.prototype.$broadcast = function() {
console.log("$broadcast was called on $scope " + $scope.$id + " with arguments:",
arguments);
return origBroadcast.apply(this, arguments);
};
Scope.prototype.$emit = function() {
console.log("$emit was called on $scope " + $scope.$id + " with arguments:",
arguments);
return origEmit.apply(this, arguments);
};
return $delegate;
});
});
๋ค์์ ๊ฐ๋จํ ์์ ๋๋ค. http://plnkr.co/edit/cn3MZynbpTYIcKUWmsBi?p=preview
์์ผ๋ก๋ ๋ฌธ์ ๋ฅผ ๊ฒ์ํ๊ธฐ ์ ์ ๋ฉ์ผ๋ง ๋ฆฌ์คํธ , IRC ์ฑ๋ ๋๋ stackoverflow์ ๋ฌธ์ํ๋ ๊ฒ์ ๊ณ ๋ คํ์ญ์์ค. ๊ทธ๋ฌ๋ ์ด๊ฒ์ ์ฃผ๋ก ๋ฒ๊ทธ ์ถ์ ์ ์ํ ๊ฒ์ ๋๋ค.
์ข์ ์์ฐ. ์ผ์ดํ๋ฆฐ ๊ฐ์ฌํฉ๋๋ค.
๋ํ, ์ฃผ๋ชฉ; ๋ด ์ค์
2014๋
1์ 29์ผ ์์์ผ Caitlin Potter [email protected]
์ผ๋ค:
์์ผ๋ก๋ ๋ฉ์ผ๋ง ๋ฆฌ์คํธ https://groups.google.com/forum/#!forum/angular ,
IRC ์ฑ๋ http://webchat.freenode.net/?channels=angularjs ๋๋
๋ฌธ์ ๋ฅผ ๊ฒ์ํ๊ธฐ ์ ์ stackoverflow http://stackoverflow.com/questions/tagged/angularjs ๊ทธ๋ฌ๋ --- ์ด๊ฒ์ ์ฃผ๋ก ๋ฒ๊ทธ๋ฅผ ์ํ ๊ฒ์ ๋๋ค.
์ถ์ .โ
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ฑฐ๋ Gi tHubhttps://github.com/angular/angular.js/issues/6043#issuecomment -33610626์์ ํ์ธํ์ธ์.
.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๊ฒ์ ์ค๋ฒํค๋๋ก ์ธํด ๊ทํ๊ฐ ๋งํ๋ฏ์ด ๊ตฌํ๋ ๊ฐ๋ฅ์ฑ์ด ์๋ ๊ฒ์ด ์๋๋๋ค.
๊ทธ๋ฌ๋ ์์ ์ ์ฑ์ ์๋ฆฌ๋ฏธ๋ฅผ ๊ตฌํํ๋ ๊ฒ์ด ๊ฐ๋ฅํ๋ฏ๋ก ๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ์ฌ์ฉํ์ฌ ์์ ์ ์ฑ์ ์๋ฆฌ๋ ๋ฐฉ๋ฒ์ ๋ง๋ค ์ ์์ต๋๋ค.
๋ค์์ ๊ฐ๋จํ ์์ ๋๋ค. http://plnkr.co/edit/cn3MZynbpTYIcKUWmsBi?p=preview