2017-09-20 3 views
0

ng-change 레이블로 함수를 호출 할 수 없습니다. 페이지 매김은 지금까지 모든 달력 주를 나열해야하며 (38), 선택한 달력 주를 pageChanged에 나열해야합니다. 나는 getData 함수에서 $scope.currentPage을 호출하여 변경시주의 사항을 업데이트하는 방법을 알아야한다.AngularJS 함수에 대한 uib 페이지 매김 변경 -

<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>