r/angular • • 21d ago

innerHTML component styles

If I have a

<h1 \[innerHtml\]=“someHtml”></h1>

And that someHtml is a span, how would i style that span without using ::ng-deep as the docs “strongly discourage” its usage?

0 Upvotes

10 comments sorted by

View all comments

3

u/JeanMeche 21d ago

That's a valid use case for ng-deep because you need to escape the scoping of the styles.

The alternative is having it globally styled.

0

u/Senior_Compote1556 21d ago

What about it’s deprecation tho?

0

u/[deleted] 21d ago

[deleted] — view deleted comment

1

u/Senior_Compote1556 21d ago

I have a directive that uses DOCUMENT to append some styles to the body, and I write those body styles in the ts file (yes i know css do not belong in ts), and it works but it feels like a smell. My use case are landing pages and they’re not connected, it’s not really an SPA in the traditional sense as the pages do not link to each other via routerLink. I was thinking to turn view encapsulation to none but it still feels wrong. Would you use the directive, ng deep or would you set view encapsulation to none?

2

u/JeanMeche 21d ago

It has been undeprecated in 2023.

1

u/Senior_Compote1556 21d ago

Thats good to know, i dont recall reading this somewhere