I try to access my scope variables in link, but they appear undefined
function tablePagination() {
return {
restrict: 'E',
template: require('./tablePagination.html'),
scope: {
currentPage: '=',
totalPages: '=',
totalCount: '=',
perPage: '='
},
link: function (scope) {
console.log(scope.currentPage, scope)
}
}
}
module.exports = tablePagination
I also tried using @, not =changing the binding using {{}}, but still undefined. I could use $observe, but I want to immediately get the values for several attributes to do some calculations. What is the best way to do this?
HTML code
<table-pagination
current-page="$ctrl.tableMeta.currentPage"
total-count="$ctrl.tableMeta.totalCount"
total-pages="$ctrl.tableMeta.totalPages"
per-page="$ctrl.tableMeta.perPage"></table-pagination>
The UPDATE . I wonder if it is because the directive does not get updated values from $ctrl.tableMetathat come from API / Async
!: , , , $watch, , undefined, async API
scope.$watch('currentPage', () => {
scope.start = (scope.currentPage - 1) * scope.perPage + 1
scope.end = Math.min(scope.currentPage * scope.perPage, scope.totalCount)
})