将Javascript添加到Angular控制器

时间:2016-03-16 09:12:47

标签: javascript angularjs ionic-framework

我正在尝试将Javascript添加到Ionic中的控制器。我的JS语法不太正确,有人可以看看。

我认为JS必须被标记为每个代码块的某种形式的范围?

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>

1 个答案:

答案 0 :(得分:0)