aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLucas Galfasó2013-07-12 17:20:40 -0300
committerPawel Kozlowski2013-07-14 16:36:15 +0200
commita170fc1a749effa98bfd1c2e1b30297ed47b451b (patch)
treebaab3aa9b9fa89e5862741288131ed9bbe20ebd1 /src
parent1e649c5a813d81ec83a0e0eda35dc7477ac98784 (diff)
downloadangular.js-a170fc1a749effa98bfd1c2e1b30297ed47b451b.tar.bz2
feat(ngPluralize): add alternative mapping using attributes
Add an alternative way to define a mapping for ng:pluralize using attributes instead of the `when` attribute Closes #2454
Diffstat (limited to 'src')
-rw-r--r--src/ng/directive/ngPluralize.js13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/ng/directive/ngPluralize.js b/src/ng/directive/ngPluralize.js
index 6ab1e182..1cefc476 100644
--- a/src/ng/directive/ngPluralize.js
+++ b/src/ng/directive/ngPluralize.js
@@ -174,13 +174,20 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
restrict: 'EA',
link: function(scope, element, attr) {
var numberExp = attr.count,
- whenExp = element.attr(attr.$attr.when), // this is because we have {{}} in attrs
+ whenExp = attr.$attr.when && element.attr(attr.$attr.when), // we have {{}} in attrs
offset = attr.offset || 0,
- whens = scope.$eval(whenExp),
+ whens = scope.$eval(whenExp) || {},
whensExpFns = {},
startSymbol = $interpolate.startSymbol(),
- endSymbol = $interpolate.endSymbol();
+ endSymbol = $interpolate.endSymbol(),
+ isWhen = /^when(Minus)?(.+)$/;
+ forEach(attr, function(expression, attributeName) {
+ if (isWhen.test(attributeName)) {
+ whens[lowercase(attributeName.replace('when', '').replace('Minus', '-'))] =
+ element.attr(attr.$attr[attributeName]);
+ }
+ });
forEach(whens, function(expression, key) {
whensExpFns[key] =
$interpolate(expression.replace(BRACE, startSymbol + numberExp + '-' +