Reputation: 531
I have the following code
var span = document.createElement('span');
Polymer.dom(span).setAttribute('class','right-icon dfw-remove-icon dfw-24');
this.listen(span, 'tap', '_removeIt');
return span;
This segment of code is from an older project that uses Polymer 1 but I'm trying to make an application using Polymer 2. The third line doesn't work for me on Chrome, it gives me an error saying this.listen is not a function. How would I set a listener on the span element so that it triggers _removeIt() when clicked on?
Upvotes: 2
Views: 82
Reputation: 138276
this.listen
equvialentthis.listen()
effectively calls addEventListener()
, so the equivalent of:
this.listen(span, 'tap', '_removeIt');
is:
span.addEventListener('tap', e => this._removeIt(e));
click
instead of tap
In Polymer 1, tap
was recommended for cross-platform consistency in handling clicks/taps. However, in Polymer 2, tap
is no longer recommended as the default, given the advances of modern mobile browsers. You should use click
instead of tap
.
Polymer.dom(span)
There's no need to call Polymer.dom(span)
if span is an element created with document.createElement()
.
Upvotes: 2