angularUtils icon indicating copy to clipboard operation
angularUtils copied to clipboard

dirPagination: Syntax error is thrown when the value of paganation-id starts with a digit

Open imdark opened this issue 8 years ago • 1 comments

I am using angular-utils-pagination#^0.11.1

the issue is pretty easy to solve by adding

Steps to reproduce: pass dirPaganation paganation-id="1" it will throw syntax error on compile the source of the issue is that $parse will throw if the a string passed to is not a valid variable name such as the string '1122aasd' , adding an '_' int the beginning fixes it


function makeCurrentPageGetterFn(scope, attrs, paginationId) {
            var currentPageGetter;
            if (attrs.currentPage) {
                currentPageGetter = $parse(attrs.currentPage);
            } else {
                // If the current-page attribute was not set, we'll make our own.
                // Replace any non-alphanumeric characters which might confuse
                // the $parse service and give unexpected results.
                // See https://github.com/michaelbromley/angularUtils/issues/233
                var defaultCurrentPage = '_'  +(paginationId + '__currentPage').replace(/\W/g, '_'); <-- this line
                scope[defaultCurrentPage] = 1;
                currentPageGetter = $parse(defaultCurrentPage);
            }
            return currentPageGetter;
        }

http://plnkr.co/edit/5Dw8dmggkQNCZfrfgPgB?p=preview

imdark avatar Sep 22 '16 03:09 imdark

Hi,

We've run across this issue before in another form: https://github.com/michaelbromley/angularUtils/issues/128#issuecomment-78516645 - comes down to the idea that the identifier (id) must be a valid JavaScript identifier. I wrote about it here: http://www.michaelbromley.co.uk/blog/410/a-note-on-angular-expressions-and-javascript-identifiers

The PR looks like a nice simple solution to this particular case. We could even take it further and do some sort of substitution for other illegal characters such as hyphens.

When I get some time to work on this I will incorporate this change (might be a few weeks due to my current schedule). Thanks for taking the time to put in the PR 👍

michaelbromley avatar Sep 22 '16 20:09 michaelbromley