Skip to content Skip to sidebar Skip to footer

Linking 2 Custom Elements Through Parent

I have 2 custom child elements that I am trying to pass data between through a parent element. My code in the parent html looks something like this:

Solution 1:

Passing an Object from one child element to another is one of the easy approaches at Polymer. Please refer for more information :

  <child-elem1 id="ch1" datamodel="{{datamodel}}" ></child-elem1>
  <child-elem2 id="ch2" datamodel="{{datamodel}}" ></child-elem2>

at child-elem2:

 ....
 <div>At child Element -2 : [[datamodel.name]]</div>
 ....
 classChildElem2extendsPolymer.Element {
      staticgetis() { return'child-elem2'; }
      staticgetproperties() { return { 
        datamodel: {
            type:Object,
            notify:true
        }
     }};
    staticgetobservers() { return []}

      ready() {
            super.ready();
            setTimeout(()=>{
                this.set('datamodel.name', 'John Doe') //our famous developer Hero :) 
            },900)
        }


 }
customElements.define(ChildElem2.is, ChildElem2);
 });

DEMO ( A similar one)

Post a Comment for "Linking 2 Custom Elements Through Parent"