Search code examples
javascripthtmlpolymer

how to get the "index-as" value from html to javascript through on-tap function?


I tried this but it is not working, the parentIndex value is not defined in javascript

_addAttribute: function(e) {
  console.log(e.model.parentIndex);
}
I wrote html like this

<paper-button on-tap="_addAttribute(this.parentIndex)">Add</paper-button>
<template id="[[count]]" is="dom-repeat" items="{{parameters}}" index-as="parentIndex" restamp>


Solution

  • You need to remove this.parentIndexin paper-button element like:

    <paper-button on-tap="_addAttribute">Add</paper-button>
    

    you will still e property inside the function. Polymer does not support sending a property to function like JS. Just console log e.model