FB Like按钮显示出来只有一次 - 我AngularJS鉴于第一负荷 [英] FB Like button shows up only once - on first load of my AngularJS view

查看:158
本文介绍了FB Like按钮显示出来只有一次 - 我AngularJS鉴于第一负荷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的地方,如按钮FB上建立在角JS我的单页网站。等按钮在由控制器显示的视图(比的index.html不同),以进行显示。但像按钮显示了只针对我第一次加载特定视图。该按钮显示不出来,如果​​我访问另一个视图后回来。
下面是一个加载FB SDK在控制器视图的code -

I am trying to place the FB like button on my single page site built on Angular JS. The like button has to be displayed on a view (different than the index.html) displayed by a controller. But the like button shows up only for the first time I load that particular view. The button do not show up if I come back after visiting another view. Below is the code which loads FB SDK in the controller for the view -

(功能(D,S,ID){结果
      变种JS,FJS = d.getElementsByTagName(多个)[0];
      如果(d.getElementById(ID)){搜索
      返回;
      }
      JS = d.createElement(S); js.id = ID;
      js.src =//connect.facebook.net/en_US/all.js#xfbml=1;
      fjs.parentNode.insertBefore(JS,FJS);
      }(文件,脚本,Facebook的jssdk'));

(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {
return; } js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));

的index.html 具有以下code -

index.html has the following code-

<机身NG控制器=mainController>

<body ng-controller="mainController">

&LT; D​​IV ID =FB-根>

<div id="fb-root">

myView.html

&LT; D​​IV CLASS =FB状数据HREF =mySite.com / {{产品id}}数据 - >布局=标准数据动作=喜欢的数据显示,面孔=假数据共享=TRUE>

<div class="fb-like" data-href="mySite.com/{{ProductID}}" data-> layout="standard" data-action="like" data-show-faces="false" data-share="true">

我已经试过各种方法,如使用FB.XFBML.Parse(),取消对FB SDK中的脚本标记,并在每负荷增加它(与希望它会像第一次),使用指令试图,放置FB-根格各种意见,现在我无言以对:|

I have tried various methods like using the FB.XFBML.Parse(), removing the script tag for FB sdk and adding it in every load(with the hope that it will work like the first time), tried using the directives, placing the fb-root div in various views and now I am clueless :|

我觉得这个问题是加载或再访视图刷新SDK,但我不知道。

I feel the issue is with loading or refreshing the SDK on revisiting the view but I am not sure.

威尔AP preciate任何投入,这将有助于我的前进,请让我知道如果你需要任何更多的信息。

Will appreciate any input which will help me move forward and please let me know if you need any more info.

谢谢,
 山姆。

Thanks, Sam.

推荐答案

我相信我找到了解决办法。

I believe I found the solution.

在设置你的widget脚本FB = NULL的开头;并删除如果(d.getElementById(ID))回报;

Set in the begining of your widget script FB = null; and remove the "if (d.getElementById(id)) return;"

这应该是这样的:

FB = null;
(function(d, s, id) { 
    var js, fjs = d.getElementsByTagName(s)[0];
    //if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/pt_BR/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

这篇关于FB Like按钮显示出来只有一次 - 我AngularJS鉴于第一负荷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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