How do I pass data to a slotted element in Lit?
I’ve tried…
<my-component>
<slot .mydata=“${this.mydata}”> <\slot>
<\my-component>
But doesn’t seem to work, is programmatically the only way to do this?
How do I pass data to a slotted element in Lit?
I’ve tried…
<my-component>
<slot .mydata=“${this.mydata}”> <\slot>
<\my-component>
But doesn’t seem to work, is programmatically the only way to do this?
We use slot on parent element.
Default (unnmamed) slot
<div class="parent>
<slot></slot>
</div>
Named slot
<div class="parent>
<slot name="slot-name"></slot>
</div>
Then insert html tag inside parent by using slot.
<main-parent>
<div slot="slot-name"></div>
</main-parent>
For default slot,you don't need to add slot attribute.
Note: Slot is used to insert external html inside parent element.
If you don't need to insert html, you don't need to use slot.
For pass data from parent to child.
<next-child childattr=${this.mydata} ></next-child>
For pass from child parent. You need to dispatch custom event with bubbles:true