I'm importing rss items where in description there is a lot of html code (links, paragraphs, etc...). When I'm viewing it in component's view like:
{{rss.description}}
the output in site is like:
<a href="http://link.com">Something</a> <p>Long text</p>
How can I quickly and easy parse it to html? I don't want to cross it with jQuery. Thank you
To render a html string in angular, we can use the innerHTML property by binding a string to it. The innerHTML property sanitizes the html, so that your app is safe from the cross-site scripting attacks(XSS).
To add HTML that contains Angular-specific markup (property or value binding, components, directives, pipes, ...) it is required to add the dynamic module and compile components at runtime. This answer provides more details How can I use/create dynamic template to compile dynamic Component with Angular 2.0?
Not sure if I understand your question correctly, but this might be what you want
<div [innerHTML]="rss.description"></div>
See also In RC.1 some styles can't be added using binding syntax for how to allow "unsafe" HTML.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With