Binding "unsafe" text to label


#1

Quick question to the NativeScript experts here!

I have an object defined on the typescript side:

let test = { icon: "", desc: "Settings" };

I want to use the “icon” field (which is a font-awesome icon) in my layout:

<Label text="{{ test.icon }}" class="font-awesome"></Label>

However, it renders the text as-is instead of the icon. It works if I hard-code it in the HTML, but I can’t do that for this application. In the web Angular world we had the DomSanitizer which could enable “unsafe” HTML, but is there an equivalent in NativeScript?


#2

Your icon is written in XML / HTML encoded format, when you directly apply it through JavaScript you must create the exact string version (like String.fromCharCode(0xf043)) then assign it.


#3

Oh of course, I’m an idiot. Thanks for the quick resolution.