AngularJS: Communication between directives

前端 未结 4 760
时光说笑
时光说笑 2021-01-01 05:33

I\'m writing a directive which creates an mp3/audio player. The issue is that you can have many audio players in one page. What I would like to do is when one is playing and

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-01 06:17

    You can also do $rootScope.$broadcast events like playerStarted. This event can be subscribed by all directives and they can react to this event by stopping themselves. The one thing that you need to do would be pass in the data about the player which is starting so that the new player does not stop itself as it too would subscribe to such event.

提交回复
热议问题