2016-09-26 85 views
0

我是新来的anugular js,并且在简单的模块上工作,例如Image Slider。TypeError:fn不是angularjs的completeOutstandingRequest函数

在这个模块中,我只是改变主页上的图像。一切工作正常。但是现在,我想使用一些动画,比如显示下一张图片时,之前的图片会被隐藏起来,并带有淡化效果。

要使用动画,我使用了角动画插件。当我包括这个插件为m的应用程序,然后浏览器显示错误下面给出:

TypeError: fn is not a function 
at angular.js:16299 
at completeOutstandingRequest (angular.js:4924) 
at angular.js:5312 

我的自定义图像滑动JS是:

var ps_mobile_app = angular.module('app', ['ngAnimate', 'ngRoute', 'ngCookies']); 
ps_mobile_app.directive('slider', function($timeout) { 
return { 
    restrict: 'AE', 
    replace: true, 
    scope: { 
     images: '=' 
    }, 
    link: function(scope, elem, attrs) { 
     scope.currentIndex = 0; 

     scope.next = function() { 
      scope.currentIndex < scope.images.length - 1 ? scope.currentIndex++ : scope.currentIndex = 0; 
     }; 

     scope.prev = function() { 
      scope.currentIndex > 0 ? scope.currentIndex-- : scope.currentIndex = scope.images.length - 1; 
     }; 

     scope.$watch('currentIndex', function() { 
      scope.images.forEach(function(image) { 
       image.visible = false; 
      }); 
      scope.images[scope.currentIndex].visible = true; 
     }); 

     /* Start: For Automatic slideshow*/ 

     var timer; 

     var sliderFunc = function() { 
      timer = $timeout(function() { 
       scope.next(); 
       timer = $timeout(sliderFunc, 5000); 
      }, 5000); 
     }; 

     sliderFunc(); 

     scope.$on('$destroy', function() { 
      $timeout.cancel(timer); 
     }); 

     /* End : For Automatic slideshow*/ 
    }, 
    templateUrl: 'shared/image-slider/slider.html' 
} 

});

我的图像滑块模块HTML是:

<div class="slider"> 
<div class="slide" ng-repeat="image in images" ng-show="image.visible"> 
    <img ng-src="{{image.src}}" /> 
</div> 
<div class="arrows"> 
    <a href="#" ng-click="prev()"> 
    <img src="shared/image-slider/img/left-arrow.png" /> 
    </a> 
    <a href="#" ng-click="next()"> 
    <img src="shared/image-slider/img/right-arrow.png" /> 
    </a> 
</div> 
</div> 

我正在使用米家页上面的模块:

<slider images="slider_images" /> 

有了上面的代码图像滑块,而无需使用角动画插件工作正常。但是对于Angular,我得到这个错误。经过少量分析,我认为它是由于超时功能而发生的。

任何人都可以请帮我解决这个问题吗?由于提前

回答

0

尝试

var sliderFunc = function() { 
 
      timer = $timeout(function() { 
 
       scope.next; 
 
       timer = $timeout(sliderFunc, 5000); 
 
      }, 5000); 
 
     };