michaelbromley / michaelbromley/angularUtils

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

Open
#400 1 comment 0 reactions 1 assignee View on GitHub

@michaelbromley is already working on this.

Since Sep 22, 2016.

enhancement
Dominant language
JavaScript
Stars
2k
Forks
842
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.