Goce Ribeski
Goce Ribeski

Reputation: 1372

Polymer, how to select element that is inside conditional template

Here is the Plunk with described problem:

How to select the 'model-el' that is inside conditional template:

<template is="dom-if" if="{{employees}}" id="model_template">
    <model-el 
      id="model"
      employees="{{employees}}"
    >second-child calling</model-el>  
</template>          

{{employees}} data is seated in 'attached' callback. Selecting is attempted in separate on-click call.

Goal is to access 'model-el.test()' function in the on-click event:

model-el.test();

I have tried differed ways, as:

      //var model_el = this.$.model;
      //var model_el = document.querySelector('model');
      //var model_el = this.shadowRoot.querySelector('model');

      console.log(model_el);
      //Goal
      model_el.test();

Upvotes: 1

Views: 220

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657118

this.$.... only supports elements which are statically added. For your use case use var model_el = this.$$('#model');. This is the short form of Polymer.dom(this.root).querySelector('#model')

Upvotes: 2

Related Questions