|
25 | 25 | /** |
26 | 26 | * Module |
27 | 27 | */ |
28 | | - var module; |
29 | | - try { |
30 | | - module = angular.module(moduleName); |
31 | | - } catch(err) { |
32 | | - // named module does not exist, so create one |
33 | | - module = angular.module(moduleName, []); |
34 | | - } |
35 | | - |
36 | | - module |
| 28 | + angular.module(moduleName, []) |
37 | 29 | .directive('dirPaginate', ['$compile', '$parse', 'paginationService', dirPaginateDirective]) |
38 | 30 | .directive('dirPaginateNoCompile', noCompileDirective) |
39 | 31 | .directive('dirPaginationControls', ['paginationService', 'paginationTemplate', dirPaginationControlsDirective]) |
|
47 | 39 | return { |
48 | 40 | terminal: true, |
49 | 41 | multiElement: true, |
| 42 | + priority: 100, |
50 | 43 | compile: dirPaginationCompileFn |
51 | 44 | }; |
52 | 45 |
|
|
56 | 49 | // regex taken directly from https://github.com/angular/angular.js/blob/v1.4.x/src/ng/directive/ngRepeat.js#L339 |
57 | 50 | var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); |
58 | 51 |
|
59 | | - var filterPattern = /\|\s*itemsPerPage\s*:\s*(.*\(\s*\w*\)|([^\)]*?(?=as))|[^\)]*)/; |
| 52 | + var filterPattern = /\|\s*itemsPerPage\s*:\s*(.*\(\s*\w*\)|([^\)]*?(?=\s+as\s+))|[^\)]*)/; |
60 | 53 | if (match[2].match(filterPattern) === null) { |
61 | 54 | throw 'pagination directive: the \'itemsPerPage\' filter must be set.'; |
62 | 55 | } |
|
188 | 181 | if (attrs.currentPage) { |
189 | 182 | currentPageGetter = $parse(attrs.currentPage); |
190 | 183 | } else { |
191 | | - // if the current-page attribute was not set, we'll make our own |
192 | | - var defaultCurrentPage = paginationId + '__currentPage'; |
| 184 | + // If the current-page attribute was not set, we'll make our own. |
| 185 | + // Replace any non-alphanumeric characters which might confuse |
| 186 | + // the $parse service and give unexpected results. |
| 187 | + // See https://github.com/michaelbromley/angularUtils/issues/233 |
| 188 | + var defaultCurrentPage = (paginationId + '__currentPage').replace(/\W/g, '_'); |
193 | 189 | scope[defaultCurrentPage] = 1; |
194 | 190 | currentPageGetter = $parse(defaultCurrentPage); |
195 | 191 | } |
|
0 commit comments