AngularJS:指令之间的通信 [英] AngularJS: Communication between directives

查看:161
本文介绍了AngularJS:指令之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写创建的mp3 /音频播放器一个指令。问题是,你可以有很多音频播放器在一个页面。当一个人玩,你启动一个其他的,即一个当前播放暂停我想这样做的是。我怎样才能用角指令实现这一目标?

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 you start an other, that the one currently playing pauses. How can I achieve this with angular directives?

在此先感谢!

推荐答案

您也可以做的 $ rootScope。$播出 playerStarted 事件。此事件可以被所有指令订阅,他们可以通过停止自己对此事件作出反应。有一件事,你需要做的是通过在其左右开始,使新玩家不自行停止,因为它太想订阅此情况下,球员的数据。

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.

这篇关于AngularJS:指令之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆