|
173 | 173 | </example>
|
174 | 174 | */
|
175 | 175 | var ngPluralizeDirective = ['$locale', '$interpolate', '$parse', function($locale, $interpolate, $parse) {
|
176 |
| - var BRACE = /{}/g; |
| 176 | + var BRACE = /{}/g, |
| 177 | + IS_WHEN = /^when(Minus)?(.+)$/; |
| 178 | + |
177 | 179 | return {
|
178 | 180 | restrict: 'EA',
|
179 | 181 | link: function(scope, element, attr) {
|
180 | 182 | var numberExp = attr.count,
|
181 | 183 | oneTimeCount = (numberExp.charAt(0) === ':') && (numberExp.charAt(1) === ':'),
|
182 | 184 | whenExp = attr.$attr.when && element.attr(attr.$attr.when), // we have {{}} in attrs
|
183 | 185 | offset = attr.offset || 0,
|
184 |
| - whens = scope.$eval(whenExp) || {}, |
185 |
| - whensExpFns = {}, |
| 186 | + whens = scope.$eval(whenExp) || createMap(), |
| 187 | + whensExpFns = createMap(), |
186 | 188 | startSymbol = $interpolate.startSymbol(),
|
187 | 189 | endSymbol = $interpolate.endSymbol(),
|
188 |
| - isWhen = /^when(Minus)?(.+)$/; |
| 190 | + tmpMatch; |
189 | 191 |
|
190 | 192 | forEach(attr, function(expression, attributeName) {
|
191 |
| - if (isWhen.test(attributeName)) { |
192 |
| - whens[lowercase(attributeName.replace('when', '').replace('Minus', '-'))] = |
193 |
| - element.attr(attr.$attr[attributeName]); |
| 193 | + tmpMatch = IS_WHEN.exec(attributeName); |
| 194 | + if (tmpMatch) { |
| 195 | + var whenKey = lowercase((tmpMatch[1] ? '-' : '') + tmpMatch[2]); |
| 196 | + whens[whenKey] = element.attr(attr.$attr[attributeName]); |
194 | 197 | }
|
195 | 198 | });
|
196 | 199 | forEach(whens, function(expression, key) {
|
|
0 commit comments