mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-08 23:04:45 +00:00
fix(ngPluralize): fixes ng-pluralize when using non-standard start/end symbols
Closes #1134
This commit is contained in:
parent
40f728b1aa
commit
d010e0cc7d
2 changed files with 42 additions and 2 deletions
|
|
@ -178,11 +178,14 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
|
||||||
whenExp = element.attr(attr.$attr.when), // this is because we have {{}} in attrs
|
whenExp = element.attr(attr.$attr.when), // this is because we have {{}} in attrs
|
||||||
offset = attr.offset || 0,
|
offset = attr.offset || 0,
|
||||||
whens = scope.$eval(whenExp),
|
whens = scope.$eval(whenExp),
|
||||||
whensExpFns = {};
|
whensExpFns = {},
|
||||||
|
startSymbol = $interpolate.startSymbol(),
|
||||||
|
endSymbol = $interpolate.endSymbol();
|
||||||
|
|
||||||
forEach(whens, function(expression, key) {
|
forEach(whens, function(expression, key) {
|
||||||
whensExpFns[key] =
|
whensExpFns[key] =
|
||||||
$interpolate(expression.replace(BRACE, '{{' + numberExp + '-' + offset + '}}'));
|
$interpolate(expression.replace(BRACE, startSymbol + numberExp + '-' +
|
||||||
|
offset + endSymbol));
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.$watch(function() {
|
scope.$watch(function() {
|
||||||
|
|
|
||||||
|
|
@ -133,4 +133,41 @@ describe('ngPluralize', function() {
|
||||||
expect(element.text()).toBe('Igor, Misko and 2 other people are viewing.');
|
expect(element.text()).toBe('Igor, Misko and 2 other people are viewing.');
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('interpolation', function() {
|
||||||
|
|
||||||
|
it('should support custom interpolation symbols', function() {
|
||||||
|
module(function($interpolateProvider) {
|
||||||
|
$interpolateProvider.startSymbol('[[').endSymbol('%%');
|
||||||
|
});
|
||||||
|
|
||||||
|
inject(function($compile, $rootScope) {
|
||||||
|
element = $compile(
|
||||||
|
"<ng:pluralize count=\"viewCount\" offset=\"1\"" +
|
||||||
|
"when=\"{'0': 'Nobody is viewing.'," +
|
||||||
|
"'1': '[[p1%% is viewing.'," +
|
||||||
|
"'one': '[[p1%% and one other person are viewing.'," +
|
||||||
|
"'other': '[[p1%% and {} other people are viewing.'}\">" +
|
||||||
|
"</ng:pluralize>")($rootScope);
|
||||||
|
$rootScope.p1 = 'Igor';
|
||||||
|
|
||||||
|
$rootScope.viewCount = 0;
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect(element.text()).toBe('Nobody is viewing.');
|
||||||
|
|
||||||
|
$rootScope.viewCount = 1;
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect(element.text()).toBe('Igor is viewing.');
|
||||||
|
|
||||||
|
$rootScope.viewCount = 2;
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect(element.text()).toBe('Igor and one other person are viewing.');
|
||||||
|
|
||||||
|
$rootScope.viewCount = 3;
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect(element.text()).toBe('Igor and 2 other people are viewing.');
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue