Created
October 15, 2017 17:31
-
-
Save cuonggt/351be0e287373c041cd2244fc01c3e25 to your computer and use it in GitHub Desktop.
Facbook comments directive for AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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