【发布时间】:2015-06-21 19:40:18
【问题描述】:
我正在创建一个 angularjs 指令来渲染 youtube video.using Iframe Api。 我在编译函数中调用 api。 但是编译函数本身并没有被调用。 这是笨蛋 http://plnkr.co/edit/PcpzOoYq73pKGeB7nZP5?p=preview
TimelyApp.directive('youtube', function($window) {
var directive = {};
var player;
directive.restrict = 'E';
directive.template = '<div id="myPlayer"></div>';
directive.complie = function(element, attribute) {
console.log("compile working");
var scriptTag = document.createElement("script");
scriptTag.src = "http://www.youtube.com/iframe_api";
var orignalScriptTag = document.getElementsByTagName('script')[0];
console.log(orignalScriptTag.parentNode);
orignalScriptTag.parentNode.insertBefore(scriptTag, orignalScriptTag);
var link = function($scope, element, attribute) {
$window.onYouTubeIframeAPIReady = function() {
player = new YT.Player('myPlayer', {
height: '390',
width: '670',
events: {
'onReady': onPlayerReady,
}
});
};
};
return link;
};
var onPlayerReady = function(event){
console.log(event);
player.cuePlaylist(["OG0xt2xTq4A","jOYR3k1VhUQ"]);
//event.target.playVideo();
player.playVideo();
};
return directive;
})
我做错了什么?
【问题讨论】:
标签: javascript angularjs youtube-javascript-api