Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular on video load event

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...

like image 602
Vic Avatar asked Oct 31 '22 11:10

Vic


1 Answers

Figured it out! Looks like I need to use:

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

Instead of:

$element.addEventListener(...)
like image 115
Vic Avatar answered Nov 11 '22 12:11

Vic