| Index: third_party/pkg/angular/lib/directive/ng_style.dart
|
| ===================================================================
|
| --- third_party/pkg/angular/lib/directive/ng_style.dart (revision 33054)
|
| +++ third_party/pkg/angular/lib/directive/ng_style.dart (working copy)
|
| @@ -1,45 +1,45 @@
|
| part of angular.directive;
|
|
|
| /**
|
| - * The `ngStyle` directive allows you to set CSS style on an HTML element
|
| - * conditionally.
|
| + * The `ngStyle` directive allows you to set CSS style on an HTML element conditionally.
|
| *
|
| * @example
|
| - * <span ng-style="{color:'red'}">Sample Text</span>
|
| + <span ng-style="{color:'red'}">Sample Text</span>
|
| */
|
| @NgDirective(
|
| selector: '[ng-style]',
|
| map: const { 'ng-style': '@styleExpression'})
|
| class NgStyleDirective {
|
| - final dom.Element _element;
|
| - final Scope _scope;
|
| - final AstParser _parser;
|
| + dom.Element _element;
|
| + Scope _scope;
|
|
|
| String _styleExpression;
|
| - Watch _watch;
|
|
|
| - NgStyleDirective(this._element, this._scope, this._parser);
|
| + NgStyleDirective(this._element, this._scope);
|
|
|
| + Function _removeWatch = () => null;
|
| + var _lastStyles;
|
| +
|
| /**
|
| * ng-style attribute takes an expression which evaluates to an
|
| - * object whose keys are CSS style names and values are corresponding values
|
| - * for those CSS keys.
|
| + * object whose keys are CSS style names and values are corresponding values for those CSS
|
| + * keys.
|
| */
|
| set styleExpression(String value) {
|
| _styleExpression = value;
|
| - if (_watch != null) _watch.remove();
|
| - _watch = _scope.watch(_parser(_styleExpression, collection: true), _onStyleChange);
|
| + _removeWatch();
|
| + _removeWatch = _scope.$watchCollection(_styleExpression, _onStyleChange);
|
| }
|
|
|
| - _onStyleChange(MapChangeRecord mapChangeRecord, _) {
|
| - if (mapChangeRecord != null) {
|
| - dom.CssStyleDeclaration css = _element.style;
|
| - fn(MapKeyValue kv) => css.setProperty(kv.key, kv.currentValue == null ? '' : kv.currentValue);
|
| + _onStyleChange(Map newStyles) {
|
| + dom.CssStyleDeclaration css = _element.style;
|
| + if (_lastStyles != null) {
|
| + _lastStyles.forEach((val, style) { css.setProperty(val, ''); });
|
| + }
|
| + _lastStyles = newStyles;
|
|
|
| - mapChangeRecord
|
| - ..forEachRemoval(fn)
|
| - ..forEachChange(fn)
|
| - ..forEachAddition(fn);
|
| + if (newStyles != null) {
|
| + newStyles.forEach((val, style) { css.setProperty(val, style); });
|
| }
|
| }
|
| }
|
|
|