2016-08-16 67 views
0

即時得到與UI的引導分頁未知的提供了一個錯誤:startFromFilterProviderAngularJS - 用戶界面,引導分頁錯誤

這裏是我的控制器代碼:

function observedCars($scope, $http, API, CarDetailService, $state) { 
    $http.get(API + '/car/?observed=true&offset=0&page_size=20'). 
    success(function(data) { 
    $scope.observed = data; 
    }); 

    $scope.pageSize = 5; 
    $scope.currentPage = 1; 

    $scope.selectCar = function(carId) { 
    CarDetailService.setCar(carId); 
    $state.go('taskDetails'); 
    }; 
} 

下面是HTML:

<div ng-controller="observedCars"> 
    <div ng-repeat="obv in observed['Observed CARs'] | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize" class="myCar"> 
    <div class="carId">{{ obv['Display Name'] }}</div> 
    <div class="title">{{ obv['Project Title'] }}</div> 
    <div class="status"> {{obv.Status}} </div> 
    <h4><u>Current Approver</u></h4> 
    <div class="currApp dont-break-out">{{obv['Current Approver']}}</div> 
    <h4><u>Amount</u></h4> 
    <div class="modified">${{obv.Amount | number:2}}</div> 
    <div class="carBtnWrap"> 
     <div class="viewCar"><a ng-click="selectCar(obv['CAR ID'])">View Details</a></div> 
    </div> 
    </div> 

    <ul uib-pagination total-items="observed['Observed CARs'].length" ng-model="currentPage" items-per-page="pageSize"></ul> 

</div> 

另外我應該提到它確實在「uib-pagination」按鈕部分中顯示了正確的按鈕數量。所以適量的頁面加載不會導致錯誤的數據。

我怎樣才能解決這個

感謝

回答

1

看來你不聲明或定義的startFrom過濾器。這裏有發現了一個爲例:AngularJS with AngularUI Bootsrap pagination directive doesn't hide results

app.filter('startFrom', function() { 
    return function (input, start) { 



     if (input === undefined || input === null || input.length === 0 
     || start === undefined || start === null || start.length === 0 || start === NaN) return []; 
     start = +start; //parse to int 

     try { 
      var result = input.slice(start); 
      return result; 

     } catch (e) { 

     // alert(input); 
     } 

    } 
}); 
+0

豎起大拇指!謝謝。 – agon024

1

您使用的是startFrom過濾器有以下表現:<div ng-repeat="obv in observed['Observed CARs'] | startFrom:(currentPage - 1) * pageSize | limitTo: pageSize" class="myCar">

你或許可以爲startFrom實施從你的例子複製,或者你忘了將它嵌入。常見的實現如下:

module.filter('startFrom', function() { 
    return function (input, skipCount) { 
    if (!input) return input; 
    return input.slice(skipCount); 
    }; 
}); 
+1

你的作品也是這樣我投票給你也 – agon024