Stencil: Allow a way to dangerously set html (from a string)

Created on 20 Sep 2017  路  3Comments  路  Source: ionic-team/stencil

Resources:
Before submitting an issue, please consult our docs.

Stencil version: (run npm list @stencil/core from a terminal/cmd prompt and paste output below):

@stencil/[email protected]

I'm submitting a ... (check one with "x")
[ ] bug report
[x] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

I have a need where I get a string of html that I need to render as actual html. In react, you can do something like:

<div dangerouslySetInnerHTML={{
    __html : '<h1>Test</h1>'
}} />

And that would output this:

<div>
  <h1>Test</h1>
</div>

I've tried this with stencil:

const foo = '<h1>Test</h1>';
<div>
  {foo}
</div>

And that encoded the html characters of course.

Most helpful comment

you should be able to use just innerHTML.

All 3 comments

you should be able to use just innerHTML.

You are correct, never thought to try it but for anyone else that will be wondering, this works:

const foo = '<h1>Test</h1>';

<div innerHTML={foo} />

@mitchellsimoens awesome thanks for verifying

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cjorasch picture cjorasch  路  3Comments

kensodemann picture kensodemann  路  3Comments

MatanYadaev picture MatanYadaev  路  3Comments

elmariofredo picture elmariofredo  路  3Comments

romulocintra picture romulocintra  路  3Comments