我试图访问link
我的范围变量,但他们似乎不确定角指令范围变量未定义
/** @ngInject */
function tablePagination() {
return {
restrict: 'E',
template: require('./tablePagination.html'),
scope: {
currentPage: '=',
totalPages: '=',
totalCount: '=',
perPage: '='
},
link: function (scope) {
console.log(scope.currentPage, scope) // scope.currentPage is undefined
}
}
}
// controller for authlogin
module.exports = tablePagination
我使用@
而不是=
也试过,改变了结合使用{{}}
但它仍然不确定。我可以使用$observe
,但我想一次获取多个属性的值来做一些计算。什么是最好的方法来做到这一点?
HTML代码
<table-pagination
current-page="$ctrl.tableMeta.currentPage"
total-count="$ctrl.tableMeta.totalCount"
total-pages="$ctrl.tableMeta.totalPages"
per-page="$ctrl.tableMeta.perPage"></table-pagination>
更新:不知从$ctrl.tableMeta
它,因为指令没有得到更新值是从API来/异步
解决方案!:哦,我发现我错了,我需要使用$watch
否则它得到旧值默认情况下是不确定的,因为它不是通过API设置异步尚未
scope.$watch('currentPage',() => {
scope.start = (scope.currentPage - 1) * scope.perPage + 1
scope.end = Math.min(scope.currentPage * scope.perPage, scope.totalCount)
})
提供你的HTML时,你用你的指令。 – Curiousdev
'currentPage'需要从HTML传递! –
你可以分享你的tablePagination.html吗? –