Last active
March 7, 2019 12:43
-
-
Save thachnuida/fa96616169d354e029ba to your computer and use it in GitHub Desktop.
Angular directive to embed Facebook public post
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
(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