Angularjs pubsub vs $broadcast

后端 未结 2 1915
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 02:16

I\'ve been reading up on event passing in Angularjs and I\'m not convinced that using $broadcast is a good idea.

Blogs like this one advocate getting used to $on eve

2条回答
  •  不思量自难忘°
    2020-12-09 02:42

    I was looking at this same problem. Particularly how to allow services to broadcast and subscribe to events without accessing $rootScope (bad for a few reasons). I utilized the very excellent js-signals implementation from here : http://millermedeiros.github.io/js-signals/ and wrapped it into an angular service.

    github gist here : https://gist.github.com/anonymous/b552c7fafa77427e6d06

提交回复
热议问题