0

The CSS defined in the HTML set by innerHtml is not reflected.

I tried to use bypassSecurityTrustHtml with pipe, but it doesn't work.
https://stackoverflow.com/a/59569667/3717426

How can styles be applied appropriately?

working

<h1>Normal</h1>
<div class="navbar-brand mx-auto title">Test<br class="br-sp" />(Test)</div>

not working

<h1>innerHTML</h1>
<div class="navbar-brand mx-auto title" [innerHTML]="title | safeHtml"></div>

See stackblitz for the source.

otera
  • 432
  • 5
  • 17

1 Answers1

2

You need to update the ngModule of your component of add ViewEncapsulation setted to None.
With default Emulated state, you component can't access to the styles with innerHtml.

import { ViewEncapsulation } from '@angular/core';

@Component({
  selector: "app-head",
  templateUrl: "./head.component.html",
  styleUrls: ["./head.component.scss"],
  encapsulation: ViewEncapsulation.None,
})
Gérôme Grignon
  • 3,859
  • 1
  • 6
  • 18