Skip to content

Passing objects or lists from plain HTML #2714

Answered by modmoto
modmoto asked this question in Q&A
Discussion options

You must be logged in to vote

I just found this hint in the docs:

Object, Array => If the element has the corresponding attribute, set the property value to JSON.parse(attributeValue).

So, changing the code to this, now finally passes objects.

<my-dropdown options='[{ "text": "hello" }, { "text": "hello" }]' test='{ "text": "hello"}'></my-dropdown

Now that I see it, it does make sense, as attributes can only contain text and putting a valid json string in there will parse the values the right way.

Here is the docs in question:
https://lit.dev/docs/components/properties/#conversion-type

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by modmoto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant