Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e85774f

Browse files
btfordIgorMinar
authored andcommitted
fix(ngPluralize): fixes ng-pluralize when using non-standard start/end symbols
Closes #1134
1 parent 44345c7 commit e85774f

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/ng/directive/ngPluralize.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,14 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
178178
whenExp = element.attr(attr.$attr.when), // this is because we have {{}} in attrs
179179
offset = attr.offset || 0,
180180
whens = scope.$eval(whenExp),
181-
whensExpFns = {};
181+
whensExpFns = {},
182+
startSymbol = $interpolate.startSymbol(),
183+
endSymbol = $interpolate.endSymbol();
182184

183185
forEach(whens, function(expression, key) {
184186
whensExpFns[key] =
185-
$interpolate(expression.replace(BRACE, '{{' + numberExp + '-' + offset + '}}'));
187+
$interpolate(expression.replace(BRACE, startSymbol + numberExp + '-' +
188+
offset + endSymbol));
186189
});
187190

188191
scope.$watch(function() {

test/ng/directive/ngPluralizeSpec.js

+37
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,41 @@ describe('ngPluralize', function() {
133133
expect(element.text()).toBe('Igor, Misko and 2 other people are viewing.');
134134
}));
135135
});
136+
137+
138+
describe('interpolation', function() {
139+
140+
it('should support custom interpolation symbols', function() {
141+
module(function($interpolateProvider) {
142+
$interpolateProvider.startSymbol('[[').endSymbol('%%');
143+
});
144+
145+
inject(function($compile, $rootScope) {
146+
element = $compile(
147+
"<ng:pluralize count=\"viewCount\" offset=\"1\"" +
148+
"when=\"{'0': 'Nobody is viewing.'," +
149+
"'1': '[[p1%% is viewing.'," +
150+
"'one': '[[p1%% and one other person are viewing.'," +
151+
"'other': '[[p1%% and {} other people are viewing.'}\">" +
152+
"</ng:pluralize>")($rootScope);
153+
$rootScope.p1 = 'Igor';
154+
155+
$rootScope.viewCount = 0;
156+
$rootScope.$digest();
157+
expect(element.text()).toBe('Nobody is viewing.');
158+
159+
$rootScope.viewCount = 1;
160+
$rootScope.$digest();
161+
expect(element.text()).toBe('Igor is viewing.');
162+
163+
$rootScope.viewCount = 2;
164+
$rootScope.$digest();
165+
expect(element.text()).toBe('Igor and one other person are viewing.');
166+
167+
$rootScope.viewCount = 3;
168+
$rootScope.$digest();
169+
expect(element.text()).toBe('Igor and 2 other people are viewing.');
170+
});
171+
})
172+
});
136173
});

0 commit comments

Comments
 (0)