AngularJS-使用指令调用Javascript函数
单击视频url时,我使用下面的指令来附加html并调用VLC对象AngularJS-使用指令调用Javascript函数,javascript,angularjs,angularjs-directive,vlc,Javascript,Angularjs,Angularjs Directive,Vlc,单击视频url时,我使用下面的指令来附加html并调用VLC对象 myApp.directive('vlcObject', function ($compile, $rootScope,$timeout) { var linker = function (scope, element, attrs) { $timeout(function () { var vlcPlayerTemplate = '<objec
myApp.directive('vlcObject', function ($compile, $rootScope,$timeout) {
var linker = function (scope, element, attrs) {
$timeout(function () {
var vlcPlayerTemplate =
'<object id="vlc" classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921" class="vlc" codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab" width="100%" height="100%">' +
' <param name="Src" value="SomeUrl"></param>' +
' <param name="autoplay" value="true" ></param>' +
' <param name="toolbar" value="false"></param>' +
' <embed type="application/x-vlc-plugin" name="vlcfirefox" autoplay="yes" toolbar="false" width="100%" height="100%" target="SomeUrl"></embed>' +
'</object>';
element.html(vlcPlayerTemplate);
$compile(element.contents())(scope);
});
};
return {
restrict: "E",
replace: true,
link: linker
};
});
随后,当用户单击播放/暂停按钮时,我将使用以下功能执行相同的操作
<input type="button" id="PlayOrPause" style="width:60px" value="Play" onClick='doPlayOrPause();'>
<input type="button" value="Stop" onClick='doStop();'>
function doPlayOrPause()
{
var vlc = getVLC("vlc");
if( vlc )
{
if( vlc.playlist.isPlaying )
vlc.playlist.togglePause();
else
vlc.playlist.play();
}
}
function doStop()
{
var vlc = getVLC("vlc");
if( vlc )
vlc.playlist.stop();
}
函数doPlayOrPause()
{
var vlc=getVLC(“vlc”);
if(vlc)
{
if(vlc.playlist.isplay)
vlc.playlist.togglePause();
其他的
vlc.playlist.play();
}
}
函数doStop()
{
var vlc=getVLC(“vlc”);
if(vlc)
vlc.playlist.stop();
}
如何使用指令调用上述JS函数 您应该为您的指令创建一个控制器,并在其中包含您需要的任何行为。此外,您可能应该为指令使用
模板
选项,而不是手动更新HTML代码>我如何从控制器调用JS函数?您是否可以将其作为与此问题相关的答案发布?您应该为您的指令创建一个控制器,并在其中包含您需要的任何行为。此外,您可能应该为指令使用模板
选项,而不是手动更新HTML代码>我如何从控制器调用JS函数?你能把它作为这个问题的答案吗
function getVLC(name)
{
if( window.document[name] )
{
return window.document[name];
}
if( navigator.appName.indexOf("Microsoft Internet") == -1 )
{
if( document.embeds && document.embeds[name] )
return document.embeds[name];
}
else
{
return document.getElementById(name);
}
}
function registerVLCEvent(event, handler)
{
var vlc = getVLC("vlc");
if( vlc )
{
if( vlc.attachEvent )
{
// Microsoft
vlc.attachEvent(event, handler);
}
else if( vlc.addEventListener )
{
// Mozilla: DOM level 2
vlc.addEventListener(event, handler, false);
}
}
}
function unregisterVLCEvent(event, handler)
{
var vlc = getVLC("vlc");
if( vlc )
{
if( vlc.detachEvent )
{
// Microsoft
vlc.detachEvent(event, handler);
}
else if( vlc.removeEventListener )
{
// Mozilla: DOM level 2
vlc.removeEventListener(event, handler, false);
}
}
}
function doGo(targetURL)
{
var vlc = getVLC("vlc");
if( vlc )
{
vlc.playlist.items.clear();
var options = [":rtsp-tcp"];
var itemId = vlc.playlist.add(targetURL,"",options);
if( itemId != -1 )
{
// play MRL
vlc.playlist.playItem(itemId);
}
else
{
alert("cannot play at the moment !");
}
}
}
<input type="button" id="PlayOrPause" style="width:60px" value="Play" onClick='doPlayOrPause();'>
<input type="button" value="Stop" onClick='doStop();'>
function doPlayOrPause()
{
var vlc = getVLC("vlc");
if( vlc )
{
if( vlc.playlist.isPlaying )
vlc.playlist.togglePause();
else
vlc.playlist.play();
}
}
function doStop()
{
var vlc = getVLC("vlc");
if( vlc )
vlc.playlist.stop();
}