Do you guys know how I can batch inject style declarations in a component using the @HostBinding decorator?
What I am trying is:
@HostBinding('style')
get style(): CSSStyleDeclaration {
return {
background: 'red',
color: 'lime'
} as CSSStyleDeclaration;
}
In my understanding this should inject the background and color style to the component, but it does not...
I can control individual style declarations like this:
@HostBinding('style.background') private background = 'red';
but I would like to do it for all of them, please help :P
this is the full code:
@Component({
selector: 'my-app',
template: `
<div>
<h2>Hello world!</h2>
</div>
`,
})
export class App {
// This works
@HostBinding('style.color') private color = 'lime';
/* This does not work
@HostBinding('style')
get style(): CSSStyleDeclaration {
return {
background: 'red'
} as CSSStyleDeclaration;
}
*/
constructor() {}
}
and a working plunker:
https://plnkr.co/edit/CVglAPAMIsdQjsqHU4Fb?p=preview
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…