Im trying to implement directive pagination and i want to pass the number of the current page from the directive to a controller and then run a function from the controller with this argument but im getting undefined.
<account-pagination pagination-config="paginationConfig" on-change="pageChanged()">
</account-pagination>
controller:
$scope.pageChanged = function(page) {
console.log(page); // undefined
}
directive:
scope: {
paginationConfig: '=',
onChange: '&',
}
$scope.moveToPage = function(numPage) {
$scope.currentPage = numPage;
getPaginData(numPage);
}
function getPaginData(numPage) {
$scope.onChange({page: numPage});
}
template directive:
<li ng-repeat="num in numPages"><a ng-click="moveToPage(num)" ng-class="{pageActive: isActive(num)}">{{num}}</a></li>
OK i find the solution:
<account-pagination pagination-config="paginationConfig" on-change="pageChanged">
</account-pagination>
scope: {
paginationConfig: '=',
onChange: '=',
}
$scope.pageChanged = function(page) {
console.log(page);
}
$scope.moveToPage = function(numPage) {
$scope.currentPage = numPage;
$scope.onChange(numPage);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.