Skip to content

Instantly share code, notes, and snippets.

@haldun
Created May 29, 2014 12:55
Show Gist options
  • Save haldun/361aa0c1ff7bfa060e5a to your computer and use it in GitHub Desktop.
Save haldun/361aa0c1ff7bfa060e5a to your computer and use it in GitHub Desktop.
video tag for angular
.directive('fmVideo', function() {
var clearContainer = function(element) {
element.find('video').each(function(_, el) {
el.pause();
el.src = "";
});
element.empty();
};
return {
restrict: 'E',
scope: {
url: '@'
},
link: function(scope, element, attrs) {
element.bind('$destroy', function() {
clearContainer(element);
});
attrs.$observe('url', function(value) {
if (value) {
clearContainer(element);
// NOTE video is currently disabled, buggy in the box
var videoNode = document.createElement('video');
videoNode.src = value;
element.append(videoNode);
videoNode.play();
}
});
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment