| Index: third_party/pkg/angular/lib/directive/ng_style.dart
|
| diff --git a/third_party/pkg/angular/lib/directive/ng_style.dart b/third_party/pkg/angular/lib/directive/ng_style.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fa05b7230b2820e6110c7372ed726bce9db0d903
|
| --- /dev/null
|
| +++ b/third_party/pkg/angular/lib/directive/ng_style.dart
|
| @@ -0,0 +1,45 @@
|
| +part of angular.directive;
|
| +
|
| +/**
|
| + * The `ngStyle` directive allows you to set CSS style on an HTML element conditionally.
|
| + *
|
| + * @example
|
| + <span ng-style="{color:'red'}">Sample Text</span>
|
| + */
|
| +@NgDirective(
|
| + selector: '[ng-style]',
|
| + map: const { 'ng-style': '@styleExpression'})
|
| +class NgStyleDirective {
|
| + dom.Element _element;
|
| + Scope _scope;
|
| +
|
| + String _styleExpression;
|
| +
|
| + NgStyleDirective(this._element, this._scope);
|
| +
|
| + Function _removeWatch = () => null;
|
| + var _lastStyles;
|
| +
|
| +/**
|
| + * ng-style attribute takes an expression hich evals to an
|
| + * object whose keys are CSS style names and values are corresponding values for those CSS
|
| + * keys.
|
| + */
|
| + set styleExpression(String value) {
|
| + _styleExpression = value;
|
| + _removeWatch();
|
| + _removeWatch = _scope.$watchCollection(_styleExpression, _onStyleChange);
|
| + }
|
| +
|
| + _onStyleChange(Map newStyles) {
|
| + dom.CssStyleDeclaration css = _element.style;
|
| + if (_lastStyles != null) {
|
| + _lastStyles.forEach((val, style) { css.setProperty(val, ''); });
|
| + }
|
| + _lastStyles = newStyles;
|
| +
|
| + if (newStyles != null) {
|
| + newStyles.forEach((val, style) { css.setProperty(val, style); });
|
| + }
|
| + }
|
| +}
|
|
|