172
172
person2.sendKeys('Vojta');
173
173
expect(withOffset.getText()).toEqual('Di, Vojta and 2 other people are viewing.');
174
174
});
175
+ it('should reset count to 0 if count - offset is negative', function() {
176
+ var withOffset = element.all(by.css('ng-pluralize')).get(1);
177
+ var personCount = element(by.model('personCount'));
178
+ personCount.clear();
179
+ personCount.sendKeys('4');
180
+ expect(withOffset.getText()).toEqual('Igor, Misko and 2 other people are viewing.');
181
+ personCount.clear();
182
+ expect(withOffset.getText()).toEqual('Nobody is viewing.');
183
+ });
175
184
</file>
176
185
</example>
177
186
*/
@@ -189,10 +198,19 @@ var ngPluralizeDirective = ['$locale', '$interpolate', '$log', function($locale,
189
198
whensExpFns = { } ,
190
199
startSymbol = $interpolate . startSymbol ( ) ,
191
200
endSymbol = $interpolate . endSymbol ( ) ,
192
- braceReplacement = startSymbol + numberExp + '-' + offset + endSymbol ,
193
201
watchRemover = angular . noop ,
194
202
lastCount ;
195
203
204
+ var oneTimeCount = / ^ \s * : : / . test ( numberExp ) || '' ;
205
+ if ( oneTimeCount ) {
206
+ numberExp = numberExp . replace ( / ^ \s * : : / , '' ) ;
207
+ oneTimeCount = '::' ;
208
+ }
209
+ var braceReplacement = [
210
+ startSymbol , oneTimeCount , '((' , numberExp , '-' , offset ,
211
+ ') < 0 ?' , 0 , ':' , numberExp , '-' , offset , ')' , endSymbol
212
+ ] . join ( '' ) ;
213
+
196
214
forEach ( attr , function ( expression , attributeName ) {
197
215
var tmpMatch = IS_WHEN . exec ( attributeName ) ;
198
216
if ( tmpMatch ) {
@@ -205,7 +223,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', '$log', function($locale,
205
223
206
224
} ) ;
207
225
208
- scope . $watch ( numberExp , function ngPluralizeWatchAction ( newVal ) {
226
+ scope . $watch ( oneTimeCount + numberExp , function ngPluralizeWatchAction ( newVal ) {
209
227
var count = parseFloat ( newVal ) ;
210
228
var countIsNaN = isNaN ( count ) ;
211
229
0 commit comments