diff --git a/modules/angular2/directives.js b/modules/angular2/directives.js index 6a1b817ab5d9..c82875d5ba16 100644 --- a/modules/angular2/directives.js +++ b/modules/angular2/directives.js @@ -1,4 +1,5 @@ export * from './src/directives/foreach'; export * from './src/directives/if'; export * from './src/directives/non_bindable'; +export * from './src/directives/style'; export * from './src/directives/switch'; diff --git a/modules/angular2/src/directives/style.js b/modules/angular2/src/directives/style.js new file mode 100644 index 000000000000..f41f3acd3414 --- /dev/null +++ b/modules/angular2/src/directives/style.js @@ -0,0 +1,38 @@ +import {Decorator} from 'angular2/src/core/annotations/annotations'; +import {NgElement} from 'angular2/src/core/dom/element'; +import {isBlank} from 'angular2/src/facade/lang'; + +@Decorator({ + selector: '[style]', + bind: { + 'style': 'condition' + } +}) +export class Style { + element:NgElement; + constructor(el: NgElement) { + this.element = el; + } + set condition(value) { + if (value) { + this.extendStyles(value); + } + return value; + } + objectToCss(object) { + var css = ''; + for (var key in object) { + css += ''+ key +':'+ object[key] +';'; + }; + return css; + } + extendStyles(styles) { + var dom = this.element.domElement.style; + for (var key in styles) { + if (key in dom) { + dom[key] = styles[key]; + } + } + return dom; + } +}