0

I want to pass an object as a property to my custom element. Passing this object as an attribute does not work not even after stringifying it. is there a way to do something like this:

let data = [
  { name: "Peter", expand: false },
  { name: "Max", expand: false },
  { name: "Lucy", expand: true }
];

<my-dropdown-list  data="${data}"></my-dropdown-list>

data is treated as attribute in my component js file. How do i pass data as a property in to my component?

Rashed Hasan
  • 3,721
  • 11
  • 40
  • 82
sumit
  • 269
  • 3
  • 11
  • 1
    Does this answer your question? [Web Components, pass data to and from](https://stackoverflow.com/questions/50404970/web-components-pass-data-to-and-from) – thanhdx Feb 09 '20 at 05:30
  • thanks. Using getter setter it worked. Just wanted to know if there is any cleaner way to do the same . For example in angular we pass objects using properties in . Hence here we are not passing value progmatically but through html. – sumit Feb 09 '20 at 07:50
  • 1
    @sumit You are *declaring* the data in HTML, Angular (using a fair amount of code) takes part of *passing* the data.. without a Framework you have to do all that yourself. – Danny '365CSI' Engelman Feb 10 '20 at 09:10
  • yeah i agree @Danny'365CSI'Engelman. So for now i'm okay with passing property as suggested by in the first comment – sumit Feb 10 '20 at 13:35

0 Answers0