1

i was trying a sample pagination for that i have created an directive like this(am not sure its correct)

(function() {
app.directive("myPagination", function() {
    return {
        restrict: 'E',
        templateUrl: 'pag.html'
    };
 });
})();

and my pag.html is

<ul class="pagination" ng-controller="PagingController">
<li ng-repeat="x  in pageing" ng-click="change(x.pageno)"><a href="#">{{x.pageno}}</a></li>
</ul>

and my PageingController is like this

 app.controller('PagingController', function($scope) {
    $scope.$on('pageinfo', function(event, args) {
        $scope.numbtn = args.numbtn;
        $scope.totaldata = args.totaldata;
        $scope.selet = args.selet;
        $scope.starter();
    })

    $scope.starter = function() {
        $scope.pageing = [];
        let i;
        for (i = 0; i < $scope.numbtn; i++) {
            $scope.pageing[i] = i;
        }
        console.log($scope.pageing);
    }
    $scope.change = function(btnclk) {
        alert(btnclk);
    }
});

and <my-pagination></my-pagination> this is how i tried in index page. but the problem is its not showing anything even no errors can any one correct this please

3

1 Answer 1

2

Add the PageingController controller to directive instead of the template

(function() {
app.directive("myPagination", function() {
    return {
        restrict: 'E',
        templateUrl: 'pag.html',
        controller : 'PagingController'
    };
 });
})()

Demo

Make sure subscriber event $on is executing. otherwise page array is empty

Sign up to request clarification or add additional context in comments.

6 Comments

i tried this but getting Error: ng:areq Bad Argument Argument 'PageingController' is not a function, got undefined error
spelling mistake should be PagingController
now its not getting error...but <my-pagination></my-pagination> is not displaying..am i wrong anywhere else..?
try to remove on function and add this $scope.pageing = [{pageno : 1},{pageno : 2}] array. Check and tell me is it working
i alredy updated it like this ` $scope.pageing=[];` $scope.pageing.push({pageno :i});but no result
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.