You have two options.
@Component({ selector : 'my-component', host : { '[style.color]' : "'red'", '[style.background-color]' : 'backgroundColor' } }) class MyComponent { backgroundColor: string; constructor() { this.backgroundColor = 'blue'; } }
- Use the
styles property and :host
@Component({ selector : 'my-component', styles : [` :host { color: red; background-color: blue; } `] }) class MyComponent {}
Note there is an odd behavior when using :host and ViewEncapsulation.None .
Here plnkr with simple examples for both alternatives.
source share