我试图实现指令分页,我想将当前页面的编号从指令传递给控制器,然后使用此参数从控制器运行一个函数,但我得到了未定义。
<account-pagination pagination-config="paginationConfig" on-change="pageChanged()">
</account-pagination>
控制器:
$scope.pageChanged = function(page) {
console.log(page); // undefined
}
指令:
scope: {
paginationConfig: '=',
onChange: '&',
}
$scope.moveToPage = function(numPage) {
$scope.currentPage = numPage;
getPaginData(numPage);
}
function getPaginData(numPage) {
$scope.onChange({page: numPage});
}
模板指令:
<li ng-repeat="num in numPages"><a ng-click="moveToPage(num)" ng-class="{pageActive: isActive(num)}">{{num}}</a></li>
答案 0 :(得分:0)
好的,我找到了解决方案:
<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);
}