homeApp.controller('BannerSliderController',function($scope,$timeout,$http) {
$scope.images=$http.get().then(function(response){
reutrn response;
});
$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,500);
},5000);
};
sliderFunc();
$scope.$on('$destroy',function(){
$timeout.cancel(timer);
});
});
我需要全局使用http响应有人可以帮助我的代码运行.................我使用了所有可能的解决方案。提前谢谢