javascript - AngularJS - Call Directive from Controller on ng-click -
html
<li> <a ng-href ng-click="startstreaming(camera);">{{camera.name}}<i class="fa fa-tv"></i></a> </li> <object events="true" id="vlc" codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab" classid="clsid:9be31822-fdad-461b-ad51-be1d1c159921"> <embed width="800" height="650" loop="no" autoplay="yes" version="videolan.vlcplugin.2" type="application/x-google-vlc-plugin" id="vlc" embed-src="" src=""> </object>
ctrl
cameramodule.controller('streamingctrl', ['$scope', '$rootscope', 'cameramoduleserviceapi', '$timeout', 'svc', '$q', 'sharedservice','mysharedservice', function ($scope, $rootscope, cameramoduleserviceapi, $timeout, svc, $q, sharedservice, mysharedservice) { var rtspobj = null; $scope.startstreaming = function (data) { // request start streaming var jason_start_streme = { "start_streamer_request": { "command ": 1, "cameraid": 123, "streamingmedium": 0 } }; cameramoduleserviceapi.start_streme(jason_start_streme).then(function (data) { $rootscope.$watch(svc.getmessage, function (v) { $timeout(function () { if (v != '') { rtspobj = angular.fromjson(v.content); $rootscope.camerartspurl = rtspobj.start_streamer_response.rtspurl; console.log("camera click : " + $rootscope.camerartspurl); sharedservice.prepforbroadcast($rootscope.camerartspurl); $scope.$apply(); } }); }); };
directive
myapp.directive('embedsrc', function () { return { restrict: 'a', link: function (scope, element, attrs) { var current = element; scope.$watch(attrs.embedsrc, function () { var clone = element.clone().attr('src', scope.camerartspurl); current.replacewith(clone); current = clone; }); } }; });
requirement:
when function startstreaming
called, video url fetched in controller , directive called change embed
src , play video.
how can call directive when startstreaming clicked, passing video url controller directive , changing embed src ?
Comments
Post a Comment