2017-09-20 8 views
0

ng-changeラベルで関数を呼び出すことができません。ページネーションは今までのすべてのカレンダー週をリストし(38)、選択したカレンダー週をpageChangedにリストする必要があります。変更の週を更新するには、getData関数の$scope.currentPageを呼び出す方法を知る必要があります。AngularJS関数での改ページの変更 -

<uib-pagination 
total-items="totalItems" 
ng-model="currentPage" 
max-size="maxSize" 
boundary-link-numbers="true" 
ng-change="pageChanged()"></uib-pagination> 

$scope.pageChanged = function() { 
    getData(); 
}; 
$scope.totalItems = 7; 
$scope.currentPage = 1; 
$scope.maxSize = 38; 

function getData() { 
    $http.get($auth.apiUrl() + '/api/status?cweek=' + $scope.currentPage).then(function(response) { 
    $scope.getData = response.data; 
    }, 
    function(error) { 
    alert("Could not fetch data from /api/status"); 
    }); 
} 

答えて

1

ワーキングコード:

controller.js

$scope.api = 'https://mysite'; 
$scope.getData = []; 
$scope.numPages = moment().week(); 
$scope.currentPage = moment().week() -1; 
$scope.maxSize = 5; 

function callApi(callback) { 
    $scope.currentPage = callback; 
    $http.get($scope.api + '/api/status?cweek=' + ($scope.currentPage)).then(function(response) { 
    $scope.getData = response.data; 
    // dont know how totalItems calculation is done but with this pagination will show all calendar weeks till todays week 
    $scope.totalItems = $scope.getData.length * 55; 
    }, 
    function(error) { 
    alert("Could not fetch data from /api/status"); 
    }); 
} 
    $scope.pageChanged = function() { 
    callApi($scope.currentPage); 
    console.log('Page changed to: ' + $scope.currentPage); 
}; 

callApi($scope.currentPage); 

index.htmlを

<ul uib-pagination total-items="totalItems" ng-model="currentPage" max-size="maxSize" class="pagination-sm" boundary-links="true" num-pages="numPages" ng-change="pageChanged()"></ul> 
関連する問題