Creating a unique CSS style, such as <special> </special>
, is my current task.
special {
color: #000000;
background: #ffff00;
}
I want to apply this style using innerHTML in Angular. However, it seems challenging due to the Sanitization method. I attempted to implement it like this:
result = this.sanitizer.bypassSecurityTrustHtml(result.trim());
Although the console error has disappeared, my <special>
style still does not work as expected.
Furthermore, when calculating character count using string length, result.length
includes all characters within
<special>Hi</special>
, instead of just counting "Hi" individually.
How can I effectively use the <special>
style and accurately count only displayed characters? Your insights are appreciated.
Additionally, I experimented with using a CSS class, but encountered similar issues...
.special {
color: #000000;
background: #ffff00;
}
This was paired with
<div class="special"> Hi </div>
when setting innerHTML with this string.
The
<div class="special"> Hi </div>
displays correctly without innerHTML,
and Chrome Developer Tools shows it as
<div _ngcontent-c4 class="special">Hi</div>
Do you know the significance of _ngcontent-c4
?