Search code examples
lit-element

Pass object by reference to nested lit-element


There are few nested elements and a main state object. I see that there is no way pass an object by reference like at Angular for example to be available at the bottom. I see that it is possible to work through the global environment. But it is not a clean solution.


Solution

  • if you want to pass the actual object as a property then you need to use the "dot notation" of lit-html.

    <my-el .data=${dataObject}></my-el>
    

    this is basically the same as doing

    document.querySelector('my-el').data = dataObject;