I'm trying to include css styles sent by a backend into my component template.
My server response looks like this:
serverResponse: {
content: '<div class="myClass classX">hello world</div>',
styles: '.myClass{color:red} .classX{...} ....';
}
(I know it's not a good idea to get css styles from a backend, but unfortunately I can't change it ;-)
My component template looks like this:
<style>
<!-- serverResponse.styles should be in here. But how? -->
</style>
<div [innerHTML]="serverResponse.content">
<!-- Binding to innerHTML works! -->
</div>
I have already set encapsulation to "ViewEncapsulation.None" in my component to enable styling with the <style> element.
What I have already tried is something like this:
<style [textContent]="serverResponse.styles">
But binding to textContent does not work...
I'd really appreciate your help!
<style [innerHTML]="serverResponse.styles">work? What errors do you get?