Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular component not rendering when passed as a string in a innerHtml attribute

I use an api that returns some html. Angular components are used in the html code but not shown in the application.

How can I show an angular component when it is stored as a string?

StackBlitz demo

like image 944
Niels Prins Avatar asked Mar 21 '26 14:03

Niels Prins


1 Answers

In general, this goes against how Angular works. There is no Angular feature for [innerHTML]. There are no component selectors there, not even a ViewContainerRef. Instead, because Angular exclusively trusts its own templates, any HTML, CSS, and JS that even appears somewhat suspect is eliminated as a security safeguard. So InnerHTML is outside limits.

You can try to dynamically load components and content with the ViewContainerRef.

like image 87
Ale_Bianco Avatar answered Mar 23 '26 06:03

Ale_Bianco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!