Javascript 未调用Angularjs自定义指令编译函数
我正在创建一个angularjs指令,以使用Iframe Api呈现youtube video.com。 我在编译函数中调用api。 但是没有调用编译函数itsely。 这是普朗克Javascript 未调用Angularjs自定义指令编译函数,javascript,angularjs,youtube-javascript-api,Javascript,Angularjs,Youtube Javascript Api,我正在创建一个angularjs指令,以使用Iframe Api呈现youtube video.com。 我在编译函数中调用api。 但是没有调用编译函数itsely。 这是普朗克 TimelyApp.directive('youtube',function($window){ var指令={}; var播放器; directive.restrict='E'; 指令.template=''; directive.complie=函数(元素、属性){ console.log(“编译工作”); v
TimelyApp.directive('youtube',function($window){
var指令={};
var播放器;
directive.restrict='E';
指令.template='';
directive.complie=函数(元素、属性){
console.log(“编译工作”);
var scriptTag=document.createElement(“脚本”);
scriptTag.src=”http://www.youtube.com/iframe_api";
var orignalScriptTag=document.getElementsByTagName('script')[0];
log(orignalScriptTag.parentNode);
orignalScriptTag.parentNode.insertBefore(scriptTag,orignalScriptTag);
var link=函数($scope、element、attribute){
$window.onYouTubeIframeAPIReady=函数(){
player=新的YT.player('myPlayer'{
高度:“390”,
宽度:“670”,
活动:{
“onReady”:onPlayerReady,
}
});
};
};
返回链接;
};
var onPlayerReady=函数(事件){
console.log(事件);
player.cuePlaylist([“OG0xt2xTq4A”,“jOYR3k1VhUQ]”);
//event.target.playVideo();
player.playVideo();
};
返回指令;
})
我做错了什么?打字错误。您将
compile
拼写错误为complie
。
你现在可以开始踢自己了:这能帮你解决问题吗
app.directive('myYoutube', function($sce) {
return {
restrict: 'EA',
scope: { code:'=' },
replace: true,
template: '<div style="height:400px;"><iframe style="overflow:hidden;height:100%;width:100%" width="100%" height="100%" src="{{url}}" frameborder="0" allowfullscreen></iframe></div>',
link: function (scope) {
console.log('here');
scope.$watch('code', function (newVal) {
if (newVal) {
scope.url = $sce.trustAsResourceUrl("http://www.youtube.com/embed/" + newVal);
}
});
}
};
});
app.directive('myYoutube',函数($sce){
返回{
限制:“EA”,
作用域:{code:'='},
替换:正确,
模板:“”,
链接:功能(范围){
console.log('here');
范围:$watch('code',函数(newVal){
if(newVal){
scope.url=$sce.trustAsResourceUrl(“http://www.youtube.com/embed/“+newVal);
}
});
}
};
});
app.directive('myYoutube', function($sce) {
return {
restrict: 'EA',
scope: { code:'=' },
replace: true,
template: '<div style="height:400px;"><iframe style="overflow:hidden;height:100%;width:100%" width="100%" height="100%" src="{{url}}" frameborder="0" allowfullscreen></iframe></div>',
link: function (scope) {
console.log('here');
scope.$watch('code', function (newVal) {
if (newVal) {
scope.url = $sce.trustAsResourceUrl("http://www.youtube.com/embed/" + newVal);
}
});
}
};
});