Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
167
rated 0 times [  170] [ 3]  / answers: 1 / hits: 76878  / 9 Years ago, thu, january 21, 2016, 12:00:00

Edit: a clarification for anyone who only skimmed the title, my question is about Angular 2, not 1.






I have a component template that is something like this:



<div>{{ post.body }}</div>


The object is something like:



{
title: Some Title,
body: <p>The <em>post body</em>.</p>
}


Instead of rendering the paragraph like:



The post body



it displays:



<p>The <em>post body</em>.</p>



Since it's such a common task, I looked for a built-in pipe like {{ post.body | safe }} but didn't see one.



Is there is an easy way to get that working? Is there a safe way to get that working?


More From » json

 Answers
4

In Angular2 you can use property binding to access properties of DOM elements, in your case:



<div [innerHTML]=post.body></div>

[#63618] Wednesday, January 20, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zahrafrancisr

Total Points: 176
Total Questions: 105
Total Answers: 99

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
;