Search code examples
polymerfunction-call

How to call the functions of an other element contained inside template (ShadowDOM)?


The question is simple (I hope so). Is there a way to call the function myFunctA of my-elementA from my-elementB? Or any solution that works similarly to how public functions work in Java or C?

<polymer-element name="my-elementA">  
 <template>  
 ...  
 </template>

 <script>
 Polymer({

   myFunctA : function()
   {
   ...
   }

 });
</script>
</polymer-element>

<polymer-element name="my-elementB">  
 <template>
   <my-elementA></my-elementA>  
   ...  
 </template>

 <script>
 Polymer({

   myFunctB : function()
   {
   //call myFunctA()
   }

 });
</script>
</polymer-element>

Solution

  • <polymer-element name="my-elementB">  
     <template>
       <my-elementA id="element"></my-elementA>  
       ...  
     </template>
    
     <script>
      Polymer({
    
       myFunctB : function()
       {
         this.$.element.myFunctA();
       }
    
      });
    </script>
    </polymer-element>