OLD | NEW |
(Empty) | |
| 1 part of angular.core.dom_internal; |
| 2 |
| 3 // This Directive is special and does not go through injection. |
| 4 @Decorator(selector: r':contains(/{{.*}}/)') |
| 5 class TextMustache { |
| 6 final dom.Node _element; |
| 7 |
| 8 TextMustache(this._element, |
| 9 String template, |
| 10 Interpolate interpolate, |
| 11 Scope scope, |
| 12 FormatterMap formatters) { |
| 13 String expression = interpolate(template); |
| 14 |
| 15 scope.watch(expression, |
| 16 _updateMarkup, |
| 17 canChangeModel: false, |
| 18 formatters: formatters); |
| 19 } |
| 20 |
| 21 void _updateMarkup(text, previousText) { |
| 22 _element.text = text; |
| 23 } |
| 24 } |
| 25 |
| 26 // This Directive is special and does not go through injection. |
| 27 @Decorator(selector: r'[*=/{{.*}}/]') |
| 28 class AttrMustache { |
| 29 bool _hasObservers; |
| 30 Watch _watch; |
| 31 NodeAttrs _attrs; |
| 32 String _attrName; |
| 33 |
| 34 // This Directive is special and does not go through injection. |
| 35 AttrMustache(this._attrs, |
| 36 String template, |
| 37 Interpolate interpolate, |
| 38 Scope scope, |
| 39 FormatterMap formatters) { |
| 40 var eqPos = template.indexOf('='); |
| 41 _attrName = template.substring(0, eqPos); |
| 42 String expression = interpolate(template.substring(eqPos + 1)); |
| 43 |
| 44 _updateMarkup('', template); |
| 45 |
| 46 _attrs.listenObserverChanges(_attrName, (hasObservers) { |
| 47 if (_hasObservers != hasObservers) { |
| 48 _hasObservers = hasObservers; |
| 49 if (_watch != null) _watch.remove(); |
| 50 _watch = scope.watch(expression, _updateMarkup, formatters: formatters, |
| 51 canChangeModel: _hasObservers); |
| 52 } |
| 53 }); |
| 54 } |
| 55 |
| 56 void _updateMarkup(text, previousText) { |
| 57 if (text != previousText && !(previousText == null && text == '')) { |
| 58 _attrs[_attrName] = text; |
| 59 } |
| 60 } |
| 61 } |
| 62 |
OLD | NEW |