how to stop video autoplay in angularjs

1.7k views Asked by At
<video  class="img-responsive" controls="controls" autostart="false">
<source  ng-src="{{data[0].media.split(',')[0]}}" > 
Your browser does not support HTML5 video.
</video>

autoplay was stop without angularjs. But i don't know how to stop autoplay using angular js coding.

2

There are 2 answers

3
Avnesh Shakya On BEST ANSWER

Try using directive:

  .directive("pause", function() {
     return {
      restrict: 'EA',
      scope: {
          auto: '@'
      }
      link: function(scope, ele, attrs) {
          var ele = angular.element(ele)[0];
          if(scope.auto) {
              ele.autoplay = true;
          }
          else {
              ele.autoplay = false;
          }
      }
   }
 })

In html:

<video  class="img-responsive" controls="controls" pause auto="false">
   <source  ng-src="{{data[0].media.split(',')[0]}}" > 
    Your browser does not support HTML5 video.
</video>

Hope this will work.

0
ian park On

You can check whether it has autostart attributes using angular.element('video').attr('autostart')

but I have same question. why need this? just use attributes in html