Angular.js: ๋ชจ๋“  ๋ฐฉ์†ก์„ ์บก์ฒ˜ํ•˜๊ณ  ์ฝ˜์†”์— ๊ธฐ๋กํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

์— ๋งŒ๋“  2014๋…„ 01์›” 29์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: angular/angular.js

์ด๊ฒƒ์€ ๋‚ด๊ฐ€ ์‹œ๋„ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค :

$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

๋ชจ๋“  3 ๋Œ“๊ธ€

์ด๊ฒƒ์€ ์˜ค๋ฒ„ํ—ค๋“œ๋กœ ์ธํ•ด ๊ท€ํ•˜๊ฐ€ ๋งํ–ˆ๋“ฏ์ด ๊ตฌํ˜„๋  ๊ฐ€๋Šฅ์„ฑ์ด ์—†๋Š” ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ ์ž์‹ ์˜ ์•ฑ์— ์•Œ๋ฆฌ๋ฏธ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž์‹ ์˜ ์•ฑ์— ์•Œ๋ฆฌ๋Š” ๋ฐฉ๋ฒ•์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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์—์„œ ํ™•์ธํ•˜์„ธ์š”.
.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰