Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters in Polymer 2.0 on-tap function?

I'm using Polymer 2.0 and I have a dom-repeat for different to-do cards. What I want to do is remove the card when I click on it.

So I tried this on-tap=deleteNote([[index]]) which uses the index from the dom-repeat. However Polymer doesn't execute the function.

What am I doing wrong?

like image 262
Gaetano Herman Avatar asked Apr 19 '17 20:04

Gaetano Herman


2 Answers

Another solution could be the dataset object within the event.target. You can define your properties with the data- prefix:

<div on-tap="doSomething" data-item$="[[item]]"></div>

And within your doSomething() listener you can get the dataset object:

doSomething(event) {
  const item = event.target.dataset.item;
  ...
}
like image 105
LasaleFamine Avatar answered Nov 07 '22 15:11

LasaleFamine


You can access the model via the event argument's model property.

So you can access the index from event.model.index.

like image 20
David Mulder Avatar answered Nov 07 '22 17:11

David Mulder