Skip to content

How can I render html both in component element and out component element? #296

Answered by Scipion
qlfy17 asked this question in Q&A
Discussion options

You must be logged in to vote

I'm not sure of the question. Do you mean you want to wrap what the children of the tag into your button? if so you can get the initial content with this.innerHTML as a string and do it like so:

@controller
export class PrimaryButtonElement extends HTMLElement {
  connectedCallback(){
        const initialContent = this.innerHTML;
        const itemTemplate = (content:string) => {
           return html`<button>${content}???</button>`
        }

        this.innerHTML=''
        render(itemTemplate(initialContent), this);
   }
}

You will have to get rid of it and re-render it again.
it will render:

<primary-button data-catalyst="">
    <button>new issue???</button>
</primary-button>

I hop…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by keithamus
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #294 on October 31, 2022 16:34.