In an Ionic2 application, I want to render <ion-icon>
s contained in an HTML string. The HTML string could be something along the lines of:
public explanation = "To open the menu, click the <ion-icon name='menu'></ion-icon> icon to the top left.";
The strings are stored in a translation file. When being output, I know that HTML strings are escaped by default and I tried to output the string with to prevent sanitization:
<p [innerHTML]="explanation"></p>
Problem: Now the <ion-icon>
code is not escaped, but the icon does not render either (even though the node is present in the DOM). The code works well when using regular HTML like <b>
tags.
Dynamic template evaluation?
I suspect the behavior is due to the fact that the code is directly inserted into the DOM and not evaluated by Ionic/Angular. For Angular1 there has been a large discussion here on SO. Solutions for Angular2 I have seen so far use the deprecated DynamicComponentLoader or are fairly complex.
Is there any easy solution to showing the icon? Defining two translation strings ...LEFT_OF_ICON
and ...RIGHT_OF_ICON
would work in this case, but feels a bit awkward.