How to force template strings interpolation for text?


#1

I have some text which I am fetching from a JSON source which contains placeholders, e.g.

let data = {"one": "click to start ${topic}"}

and it is rendered on an ionic view with:

<h1 [innerHtml]="data.one"></h1>

In the model I have a variable named topic="dinsdale", yet the text is rendered literally and no substitution occurs.

Some answers on SO suggest using eval, but it looks a bit scary. Does ionic have a built-in mechanism for this?


#2

If you don’t get any better answers, I pretend innerHTML doesn’t exist. Angular doesn’t want you to do this. You may be able to adapt ngx-translate to do the interpolation, or if that’s not enough, you could look at this idiom.


#3

@rapropos: Thanks! I am thinking that I will probably go with string replace and some sanitization, taking into account that topic is coming from user input.