myApp.directive('vlcControls', function ($compile, $rootScope, $timeout, $window, pictureboxConstants) {
var linker = function (scope, element, attrs) {
vlcPlayerCustomTemplate = 'some html goes here';
scope.getVLC = function (name) {
if ($window.document[name]) {
return $window.document[name];
}
if ($window.navigator.appName.indexOf("Microsoft Internet") == -1) {
if ($window.document.embeds && $window.document.embeds[name])
return $window.document.embeds[name];
} else {
return $window.document.getElementById(name);
}
}
scope.doPlayPause = function (vlcPlayer, event) {
var vlc = scope.getVLC(vlcPlayer);
if (vlc) {
if (vlc.playlist.isPlaying) {
vlc.playlist.pause();
angular.element(event.target).children().removeClass('fa fa-pause font-12');
angular.element(event.target).children().addClass('fa fa-play font-12');
} else {
if (vlc.audio.mute == true) {
//do something
}
vlc.playlist.play();
}
}
}
angular.element(document.querySelector("#controls" + index)).append(element.html(vlcPlayerCustomTemplate));
$compile(element.contents())(scope);
};
return {
restrict: "E",
link: linker
};
});
控制器
myModule.controller('myModuleCtrl', function ($scope, $http, $controller, $compile) {
$compile("<vlc-controls></vlc-controls>")($rootScope);
});
什麼是唯一的最佳方式調用特定的directive
函數/方法doPlayPause
從controller
無使用vlcPlayerCustomTemplate
html元素或任何DOM
操縱?
只是我想知道,你有機會看看我的回答下面這很好地工作像''compile'一樣,沒有'DOM'操作? – Aruna