brantwills/Angular-Paging

How to init the 'page' value when html first load

Closed this issue · 4 comments

I have a var loadParams.pageNo bind to 'page' which may not be 1, and the loadParams.pageNo is initialized according to the param in the url.

for example, if the pageNo from the url is 2, then I set the loadParams.pageNo = 2. But after the Angular-Paging init, the loadParams.pageNo is chaged to 1...

Hey justdmm,

There are checks in the paging directive which will set page to 1 if the directives scope.page is missing:
Line 28 in https://github.com/brantwills/Angular-Paging/blob/master/paging.js

scope.page = parseInt(scope.page) || 1;

Based on your description it sounds like there may be an issue in binding against the directives page value - specifically when your loadParams.pageNo is bound to the directives page scope

In my testing I have yet to have this issue although I will try to reproduce this evening - if possible could you provide some example code trapping this case - we have had some success working with URL parameters using http://codepen.io/ (see issue #17 for examples)

I figure it out, it's changed to 1 in the method validateScopeValues, and the pageCount is 0 at that time.

function validateScopeValues(scope, pageCount) {

        // Block where the page is larger than the pageCount
        if (scope.page > pageCount) {
            scope.page = pageCount;
        }

        ...
    }

Ahh yup that would do it! This make me feel like there needs to be a section in the readme about these different conditions and why they exist.

I will leave this issue open and start working on getting these validation conditions explained. Thank you for following up!

I have included a new readme file inside the source (src) folder for version 2.0.0
Within src/readme.md I have included all the sneaky validation pieces like the one listed above.
Please feel free to amend the readme if something doesn't make sense!