角JS和Addthis个事件处理器 [英] Angular JS and addthis eventhandlers

查看:223
本文介绍了角JS和Addthis个事件处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在大型项目上采用了棱角分明的第一次和的要求之一是,我们使用2007-06-18为文章社会共享。但是,除了的 2007-06-18 的共享,我们要跟踪谷歌分析的分享活动。

I'm using Angular for the first time on a large project and one of the requirements is that we use AddThis for social sharing for articles. But in addition to the AddThis sharing, we want to track the share events in google analytics.

所以,我想要做的就是添加的 2007-06-18

So what I want to do is add the AddThis

<div class="addthis_toolbox addthis_16x16_style">
  <a class="addthis_button_preferred_1"></a>
  <a class="addthis_button_preferred_2"></a>
  <a class="addthis_button_preferred_3"></a>
  <a class="addthis_button_preferred_4"></a>
  <a class="addthis_button_compact"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=XXXXX"></script>

和控制器,在他们的文档中描述添加事件处理程序
<一href=\"http://support.addthis.com/customer/portal/articles/381263-addthis-client-api-#configuration-sharing\" rel=\"nofollow\">http://support.addthis.com/customer/portal/articles/381263-addthis-client-api-#configuration-sharing

and in the controller, add an event handler as described in their docs http://support.addthis.com/customer/portal/articles/381263-addthis-client-api-#configuration-sharing

addthis.addEventListener('addthis.menu.open', eventHandler);
addthis.addEventListener('addthis.menu.close', eventHandler);
addthis.addEventListener('addthis.menu.share', eventHandler);

问题是,我似乎无法获得在控制器的$范围以Addthis个对象的引用。有谁知道我怎么可以通过指令或其他一些把戏做的document.ready,完成本入门到Addthis个对象的引用?

The problem, is that I can't seem to get a reference to the addthis object in the $scope of the controller. Does anyone know how I can accomplish this either via directive or some other trick to do a document.ready and getting a reference to the addthis object?

推荐答案

Addthis个窗口的属性和必须在任何范围内是可见的,但是我想这键入的addEventListener 不是内部addthis_widget.js评估参数

addthis is a property of window and must be visible in any scope, however I guess that type parameter of addEventListener is not evaluated inside addthis_widget.js

您是否尝试过这个?

<div class="addthis_toolbox addthis_16x16_style">
  <a class="addthis_button_preferred_1"></a>
  <a class="addthis_button_preferred_2"></a>
  <a class="addthis_button_preferred_3"></a>
  <a class="addthis_button_preferred_4"></a>
  <a class="addthis_button_compact"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=XXXXX"></script>
<script type="text/javascript">
    addthis.addEventListener('addthis.menu.open', eventHandler);
    addthis.addEventListener('addthis.menu.close', eventHandler);
    addthis.addEventListener('addthis.menu.share', eventHandler);
<script>

这样的活动应该在每次重新加载部件时应用。

That way events should be applied each time you reload the widget.

如果简化版,帮助,你可以把它包装成一个指令,像我一样这里。尝试添加该指令内你的听众。

If does't help, you can wrap it into a directive like I did here. Try to add your listeners inside the directive.

这篇关于角JS和Addthis个事件处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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