zuiderveen zuiderveen - 1 year ago 146
AngularJS Question

Angular facebook-comments directives

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.

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'));
<facebook-Comments href="{{track.share_url}}"></facebook-Comments>

This is my directive:

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);
} );

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?

Answer Source

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


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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download