Skip to content

Instantly share code, notes, and snippets.

@cuonggt
Created October 15, 2017 17:31
Show Gist options
  • Save cuonggt/351be0e287373c041cd2244fc01c3e25 to your computer and use it in GitHub Desktop.
Save cuonggt/351be0e287373c041cd2244fc01c3e25 to your computer and use it in GitHub Desktop.
Facbook comments directive for AngularJS
angular.module('directives.fbComments', [])
.directive('fbComments', fbComments);
fbComments.$injects = ['$timeout'];
function fbComments($timeout) {
function createHTML(href, numposts) {
return '<div class="fb-comments" ' +
'data-href="' + href + '" ' +
'data-numposts="' + numposts + '">' +
'</div>';
}
return {
restrict: 'A',
scope: {},
link: function postLink(scope, elem, attrs) {
elem.html(createHTML(attrs.href, attrs.numposts));
$timeout(function () {
if (typeof FB != 'undefined') {
FB.XFBML.parse(elem[0]);
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment