Skip to content

Instantly share code, notes, and snippets.

@thachnuida
Last active March 7, 2019 12:43
Show Gist options
  • Save thachnuida/fa96616169d354e029ba to your computer and use it in GitHub Desktop.
Save thachnuida/fa96616169d354e029ba to your computer and use it in GitHub Desktop.
Angular directive to embed Facebook public post
(function () {
'use strict';
/**
* @desc Direictive to embed facebook post
* @example <fb-post-preview data-href="vm.postUrl"></fb-post-preview>
*/
angular
.module('fbDirective')
.directive('fbPostPreview', fbPostPreview);
/* @ngInject */
function fbPostPreview($timeout) {
var directive = {
link: link,
template: '<div class="fb-post" data-href="{{href}}"></div>',
restrict: 'EA',
scope: {
href: '=href'
}
};
return directive;
function link(scope, element, attrs) {
$timeout(function() {
if (FB) {
FB.XFBML.parse(element[0]);
}
});
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment