I'm writing the following directive:
.directive('mypagination', function () {
return {
restrict: 'E',
scope: {
pageCount: "=",
},
template: "{{pageCount}}",
link: function ($scope, $element, $attrs) {
$scope.pages = [];
for (var i = 1; i <= $scope.pageCount; i++) {
$scope.pages.push(i);
}
}
}
})
My issue is that $scope.pageCount inside the for loop is set to 0, but {{pageCount}} in the template is rendering the correct value.
In HTML the directive is being called like this:
<mypagination page-count="mjaController.pages.length"
on-page-change="mjaController.fetchStuff(page)">
</mypagination>
Why would the value of pageCount be 0 inside the link function, but render correctly on the page?