0

I am trying to add Javascript to a controller in Ionic. My JS syntax isn't quite right, can someone please give it a look over.

I assume JS has to be tagged to some form of scope for each block of code?

CONTROLLER

.controller('ProductCtrl', function(Products, $scope, $stateParams, $state, $timeout) {
    $scope.product = Products[$stateParams.productId];

    $scope.$on('$routeChangeStart', function(next, current) { 
    var video = document.getElementById("myVideo");
    function stopVideo(){
         video.pause();
         video.currentTime = 0;
    })

    var video = document.getElementById('myVideo').addEventListener('ended',myHandler,false);
    function myHandler(e) {
       $state.go('app.home');
    })

PRODUCT.HTML

 <ion-view view-title="Individual Video">
 <ion-nav-view></ion-nav-view>
 <ion-content>
<h2>{{product.title}}</h2>
<h2>{{product.duration}}</h2>
<video id="myVideo" controls="controls" preload="metadata"  autoplay="autoplay" webkit-playsinline="webkit-playsinline"  class="videoPlayer"><source src="{{product.video}}" type="video/mp4" /></video>
</ion-content>
</ion-view>
2
  • 1
    it's hard to understand what you are actually looking for Commented Mar 16, 2016 at 9:14
  • first you declare var video twice.. Second you declare a function stopVideo but bever use it. If it has to be used with binding in the template you have to store it in $scope like this : $scope.stopVideo = function(){...}; . Thrid i don't even see the end bracket of the callback for $routeCHangeStartEvent. If you need more information please post the full content of the controller and the template where it's used. Commented Mar 16, 2016 at 9:16

1 Answer 1

0

Similar question. This might be helpful to you:

Calling AngularJS controller function when html5 video ends

Answer: https://stackoverflow.com/a/29030565/3298029

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.