解決Ionic的ion-slide-box 2條資料渲染問題

吊兒郎當發表於2016-12-06

當slider資料列表是動態獲取時,如果資料結果只有2條資料時,slider列表會多複製倆個,通過下面的slideChange方法做個判斷可以解決這個bug

 

第一步:新增slideChande方法

<ion-slide-box auto-play="true" does-continue="true" slide-interval="3000" on-slide-changed="slideChanged($index)">
  <ion-slide ng-repeat="pic in pics"><img ng-src="{{pic}}" src="" alt="" width="" height="" /></ion-slide>
</ion-slide-box>

app.controller('defaultCtrl', function($scope, $timeout, $ionicSlideBoxDelegate) {
    $scope.slideChanged = function(index) {  
        $scope.slideIndex = index;  
        if ( ($ionicSlideBoxDelegate.count() -1 ) == index ) {  
            $timeout(function(){  
                $ionicSlideBoxDelegate.slide(0);  
            },3000);  
        }  
    };
  
  $http.get('api/get/slide_pics').success(function (response) {
    $scope.pics = response.data;
  });
});

 

 第二步:更改原始檔

從原始檔(ionic.bundle.js)裡找到以下程式碼   提示:在setup()方法裡找

if (slides.length < 2) options.continuous = false;

用下面程式碼替換

if(slides.length<2){
    options.initialContinuous=options.continuous;
    options.continuous=false;
}elseif(options.initialContinuous){
    options.continuous=options.initialContinuous;
}

 

 

相關文章