172
172
</file>
173
173
</example>
174
174
*/
175
- var ngPluralizeDirective = [ '$locale' , '$interpolate' , function ( $locale , $interpolate ) {
175
+ var ngPluralizeDirective = [ '$locale' , '$interpolate' , '$parse' , function ( $locale , $interpolate , $parse ) {
176
176
var BRACE = / { } / g;
177
177
return {
178
178
restrict : 'EA' ,
179
179
link : function ( scope , element , attr ) {
180
180
var numberExp = attr . count ,
181
+ oneTimeCount = ( numberExp . charAt ( 0 ) === ':' ) && ( numberExp . charAt ( 1 ) === ':' ) ,
181
182
whenExp = attr . $attr . when && element . attr ( attr . $attr . when ) , // we have {{}} in attrs
182
183
offset = attr . offset || 0 ,
183
184
whens = scope . $eval ( whenExp ) || { } ,
@@ -198,20 +199,36 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
198
199
offset + endSymbol ) ) ;
199
200
} ) ;
200
201
201
- scope . $watch ( function ngPluralizeWatch ( ) {
202
- var value = parseFloat ( scope . $eval ( numberExp ) ) ;
202
+ if ( oneTimeCount ) {
203
+ scope . $watch ( numberExp , function ngPluralizeWatchOneTimeAction ( newVal ) {
204
+ var value = parseFloat ( newVal ) ;
205
+ var text = '' ;
203
206
204
- if ( ! isNaN ( value ) ) {
205
- //if explicit number rule such as 1, 2, 3... is defined, just use it. Otherwise,
206
- //check it against pluralization rules in $locale service
207
- if ( ! ( value in whens ) ) value = $locale . pluralCat ( value - offset ) ;
208
- return whensExpFns [ value ] ( scope ) ;
209
- } else {
210
- return '' ;
211
- }
212
- } , function ngPluralizeWatchAction ( newVal ) {
213
- element . text ( newVal ) ;
214
- } ) ;
207
+ if ( ! isNaN ( value ) ) {
208
+ //if explicit number rule such as 1, 2, 3... is defined, just use it. Otherwise,
209
+ //check it against pluralization rules in $locale service
210
+ if ( ! ( value in whens ) ) value = $locale . pluralCat ( value - offset ) ;
211
+ text = whensExpFns [ value ] ( scope ) ;
212
+ }
213
+
214
+ element . text ( text ) ;
215
+ } ) ;
216
+ } else {
217
+ scope . $watch ( function ngPluralizeWatch ( ) {
218
+ var value = parseFloat ( scope . $eval ( numberExp ) ) ;
219
+
220
+ if ( ! isNaN ( value ) ) {
221
+ //if explicit number rule such as 1, 2, 3... is defined, just use it. Otherwise,
222
+ //check it against pluralization rules in $locale service
223
+ if ( ! ( value in whens ) ) value = $locale . pluralCat ( value - offset ) ;
224
+ return whensExpFns [ value ] ( scope ) ;
225
+ } else {
226
+ return '' ;
227
+ }
228
+ } , function ngPluralizeWatchAction ( newVal ) {
229
+ element . text ( newVal ) ;
230
+ } ) ;
231
+ }
215
232
}
216
233
} ;
217
234
} ] ;
0 commit comments