AngularJS + Facebook的类似指令无法正常工作 [英] AngularJS + Facebook like Directive not working

查看:107
本文介绍了AngularJS + Facebook的类似指令无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯开发一个应用程序AngularJs至极视图中的集成FB-等。它只能一次,如果我刷新浏览器也,当我浏览到其他视图和复出插件无法正常工作。

Im developing an AngularJs Application wich integrates fb-like in a view. It only works first time and if I refresh the browser also, when I navigate to other view and comeback the plugin does not work.

我创建了一个指令。

angular.module('myApp.directives', []).directive('fbLike',['$timeout', function($timeout) {
return {
    restrict: 'A',
    scope: {},
    template: "<div class=\"fb-like-box\" data-href=\"{{page}}\" data-width=\"{{width}}\" data-show-faces=\"{{faces}}\" data-height=\"{{height}}\" data-show-border=\"{{border}}\" data-stream=\"{{stream}}\" data-header=\"{{header}}\"></div>",
    link: function($scope, $element, $attrs) {
        var working, _ref, _ref1;

        $scope.page ="https://www.facebook.com/company_name";
        $scope.border = false;
        $scope.height = (_ref = $attrs.fbHeight) != null ? _ref : '260';
        $scope.faces = $attrs.fbFaces != null ? $attrs.fbFaces : 'false';
        $scope.stream = $attrs.fbStream != null ? $attrs.fbStream : 'true';
        $scope.header = $attrs.fbHeader != null ? $attrs.fbHeader : 'false';
        $scope.width = (_ref1 = $attrs.fbWidth) != null ? _ref1 : $element.parent().width()-19;
        $timeout(function () { return typeof FB !== "undefined" && FB !== null ? FB.XFBML.parse($element.parent()[0]): void 0; });
    }
};}]);

我的看法

    <script>

window.fbAsyncInit = function() {
 FB.init({

appId: '',
     status: true, // check login status
     cookie: true, // enable cookies to allow the server to access the session
     xfbml: true,  // parse XFBML
     oauth: true

   });

  };

(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/es_LA/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

</script>

<div fb-like></div>

我一直在寻找其他的选项,但是没有幸运的。

I was looking for other option but no lucky.

我不知道什么是错。

感谢你这么多。

推荐答案

我发现最好的解决办法就是添加ezfb模块,我的应用程序,现在它的伟大的工作。

Best solution I found is add ezfb module to my App, now it's working great.

我全力推荐这个模块。

.config(function ($FBProvider) {
  $FBProvider.setInitParams({
    appId: '386469651480295'
  });  
})

有上Plunker演示演示

There is a demo on Plunker Demo

Github上链接

这篇关于AngularJS + Facebook的类似指令无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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