Angularjs HTML5 视频结束 [英] Angularjs HTML5 Video onended
本文介绍了Angularjs HTML5 视频结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在加载 html5 mp4 视频,我想在视频结束时从角度范围触发功能.我尝试了下面的简单代码,但 onended 事件在 angular 范围内找不到该函数.
I am loading html5 mp4 video and I want to trigger function from angular scope when video end. I tried below simple code but onended event cannot find the function in angular scope.
HTML
<video controls="controls" autoplay="true" ng-show="showVideo" ng-src="{{vidSrc}}" vid-dir onended="vidEnded()">
在主控制器中添加了 Angularjs 功能.onended 事件触发但功能未定义
Angularjs function added in main controller. onended event triggered but function is undefined
$scope.vidEnded = function(){
console.log('vid ended')
}
也试过在这样的目录中添加函数,但没有触发该函数.
Also tried adding function in directory like this but the function is not triggered.
.directive('vidDir', [function () {
return {
restrict: 'A',
link: function (scope, elem, attr) {
console.log(elem)
elem.onended = function(){
console.log('vid ended')
}
}
};
}]);
推荐答案
我相信以下代码可以实现您的愿望.
I believe the following code would achieve what you desire.
<video controls="controls" autoplay="true" ng-show="showVideo" ng-src="{{vidSrc}}" vid-dir (ended)="vidEnded()">
这篇关于Angularjs HTML5 视频结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文