I am trying to dynamically populate HTML elements in my LWC. However it is showing as text, escaping the HTML characters.
I tried using <lightning-formatted-rich-text>
but that is also not doing the trick for me.
Below is a sample of the code I've tried implementing.
HTML
<template>
<div class="wrapper"
<template for:each={tableColumnContentWrapper} for:item='contentColumn'>
<div class="row" key={contentColumn.fieldName}>
<div class="column">
<lightning-formatted-rich-text value={contentColumn.stateHtml}></lightning-formatted-rich-text>
</div>
</div>
</template>
</template>
JavaScript
import { LightningElement, track } from 'lwc';
export default class MyClass extends LightningElement {
@track tableColumnContentWrapper = [
{
fieldName: 'state',
stateHtml: '<input type="text" placeholder="Your state" class="data-input"/>'
}
];
}
This is what I see in the inspector:
Any ideas would be appreciated.
EDIT
I do understand that this is not rich-text and as such it's not inserting an <input />
element as I tested with <h1></h1>
and that seems to be working alright.
I can modify the innerHTML
but I wanted to try and see if there's a cleaner way of doing this first.
innerHTML
. – Arthlete Mar 11 '20 at 21:24