@@ -95,6 +95,8 @@ class NgPluralizeDirective {
95
95
int offset;
96
96
final discreteRules = < String , String > {};
97
97
final categoryRules = < Symbol , String > {};
98
+ final expressionCache = < String , String > {};
99
+ Watch _watch;
98
100
99
101
static final RegExp IS_WHEN = new RegExp (r'^when-(minus-)?.' );
100
102
static const Map <String , Symbol > SYMBOLS = const {
@@ -164,10 +166,14 @@ class NgPluralizeDirective {
164
166
}
165
167
}
166
168
167
- _setAndWatch (expression) {
168
- var interpolation = interpolate (expression, false , r'${' , '}' );
169
- interpolation.setter = (text) => element.text = text;
170
- interpolation.setter (expression);
171
- scope.watch (interpolation.expressions, interpolation.call);
169
+ void _setAndWatch (template) {
170
+ if (_watch != null ) _watch.remove ();
171
+ var expression = expressionCache.putIfAbsent (template, () =>
172
+ interpolate (template, false , r'${' , '}' ));
173
+ _watch = scope.watch (expression, _updateMarkup);
174
+ }
175
+
176
+ void _updateMarkup (text, previousText) {
177
+ if (text != previousText) element.text = text.toString ();
172
178
}
173
179
}
0 commit comments