I have build a component and I want to make it more reusable, so I can use it in more projects. I want to pass a stylesheet reference when I create the component on a template, something like this:
<dynamic-css [myStyle]= "route/my-stylesheet.css"></dynamic-css>
My first aproach is to link it inside the component template, something like this:
<link rel="stylesheet" [attr.href]="myStyle">
<div>My dynamic-css component content</div>
But I don't work, the console throws an error;
can't find property 'css' of undefined
Here is a dummy version of my component:
@Component({
selector:'dynamic-css',
template: `
<link rel="stylesheet" [attr.href]="myStyle">
<div>My dynamic-css component content</div>
`
})
export class DynamicCssComponent{
@Input myStyle:string;
}
Is there any aproach to pass a href correctly to the component, or other way to set a stylesheet dynamicaly?