我希望组件的用户能够传递模板的自定义样式,同时仍保留组件的ViewEncapsulation。以下示例不起作用,但类似于:
@Component({
selector: 'my-component',
template: `
<div class="myClass">
<div class="innerClass">
</div>
</div>
`,
styles: [customStyles]
})
export class CustomComponent {
// input would be CSS as a string
// ".myClass { text-align: center; }"
@Input() customStyles: string;
}
是否有一种优雅的方法?