Created
May 29, 2014 12:55
-
-
Save haldun/361aa0c1ff7bfa060e5a to your computer and use it in GitHub Desktop.
video tag for angular
This file contains hidden or 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
.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