角Facebook的评论指令 [英] Angular facebook-comments directives

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

问题描述

我是比较新的角度,所以也许我问的是非常简单的。
我想加载一个Facebook的评论框,我的想法是一个角指令做到这一点。

I'm relatively new to Angular, so maybe what I ask is really simple. I want to load a Facebook comment box, my idea is to do this with a Angular directive.

这是我的HTML code:

This is my HTML code:

<div class="comments">
<div id="fb-root"></div>
<script>(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/nl_NL/all.js#xfbml=1";
    fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>
<facebook-Comments href="{{track.share_url}}"></facebook-Comments>    
</div>

这是我的指令:

angular.module( "CommentsDirectiveModule", [] )
.directive("facebookComments", function () {
  return {
      restrict: "E",
      scope: {
          code: "@href",
      },
      replace: true,
      template: '<fb:comments href="{{ur}}" width="300" numposts="5" colorscheme="light"></fb:comments>',
      link: function(scope) {
        scope.$watch("code", function (newVal) {
          if (newVal) {
            scope.url = $sce.trustAsResourceUrl(newVal);
          }
        });
      }
  };
} );

{{} track.share_url} 传递的指令和回HTML。但问题是,有没有Facebook的评论框。

The {{track.share_url}} is passed to the directive and back to html. But the problem is that there is no Facebook comment box.

有没有人没有理由这个问题?

Does anyone no the reason for this problem?

推荐答案

我不知道如何写在angularJS我的指令工作解析功能,但这个剧本没有的伎俩对我来说:

I don't know how to write a working parse function in angularJS for my directive but this script did the trick for me:

https://github.com/pc035860/angular-easyfb

我跟着解释,用这个例子: http://plnkr.co/编辑/ gFM1LV?p = preVIEW
并添加此行到我的HTML:

I followed the explanation, used this example: http://plnkr.co/edit/gFM1LV?p=preview and added this line to my HTML:

<div class="fb-comments" data-href="{{track.share_url}}" data-width="300px" data-numposts="5" data-colorscheme="light"></div>

这篇关于角Facebook的评论指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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