What's the correct way to communicate between controllers in AngularJS?

前端 未结 19 2489
猫巷女王i
猫巷女王i 2020-11-21 22:02

What\'s the correct way to communicate between controllers?

I\'m currently using a horrible fudge involving window:

function StockSubgro         


        
19条回答
  •  梦谈多话
    2020-11-21 23:06

    Actually using emit and broadcast is inefficient because the event bubbles up and down the scope hierarchy which can easily degrade into performance bottlement for a complex application.

    I would suggest to use a service. Here is how I recently implemented it in one of my projects - https://gist.github.com/3384419.

    Basic idea - register a pubsub/event bus as a service. Then inject that eventbus where ever you need to subscribe or publish events/topics.

提交回复
热议问题