Angular on video load event

情到浓时终转凉″ 提交于 2019-12-30 06:53:59

问题


I'm still trying to understand angular...

Basically, I have an html5 video and I want to listen to the onloadeddata event (http://www.w3schools.com/jsref/event_onloadeddata.asp).

This is what I have:

html:

<video autoplay="autoplay" loaded-data loop style="display: none;">
  <source src="videos/example.mp4" type="video/mp4">
  <source src="videos/example.ogg" type="video/ogg">
</video>

directive:

angular.module('myApp')
  .directive('loadedData', function () {
    return function ($scope, $element) {
      $element.addEventListener("loadeddata", function () {
        console.log('test'); // never calls
      });
    }
});

Is this the correct way of handling this? For some reason, the event listener never gets called.

I've also tried

$element.bind('loadedData', function () {
    console.log('test');
});

but it also doesn't work...


回答1:


Figured it out! Looks like I need to use:

$element[0].addEventListener(...)

Instead of:

$element.addEventListener(...)



回答2:


$element.on('loadeddata', function (event) {
   var width = $element[0].videoWidth;
}

'loadeddata' works for me 'loadedData' does not



来源:https://stackoverflow.com/questions/28016476/angular-on-video-load-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!