question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to pass parameter to listener?

See original GitHub issue

image

.bind must not be used in templates, a method should be passed directly like ${this.myMethod} as it will be bound automatically.eslint(lit/no-template-bind)

So, what is the best practice to pass parameters to an event listener?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Westbrookcommented, Sep 18, 2019

The most immediate version of what you’re attempting is to use fat arrow syntax in this context:

return html`
    <button @click=${() => this.cancelClick_cb(record)}></button>
`;
2reactions
qqiaocommented, Sep 18, 2019

I thought the simplest would just be:

// Pseudo code
<button record='${record}' @click="clickHandler">

clickHandler(e) {
    const target = e.target;
    if ('BUTTON' != target.tagName) return;
    const record = target.record;
    // do the rest
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass arguments to addEventListener listener function?
getElementById('your-button') button_element.setAttribute('your-parameter-name',your-parameter-value); button_element.addEventListener('click' ...
Read more >
Passing Arguments to Event Listeners in JavaScript
Passing arguments to an event handler can be particularly useful when the handler is reused for different events. For example, we want to...
Read more >
How to pass arguments to addEventListener listener function
Here is the code: var someVar = some_other_function(); someObj.addEventListener("click", function(){ some_function(someVar); }, false);.
Read more >
EventTarget.addEventListener() - Web APIs | MDN
Event listener with anonymous function. Here, we'll take a look at how to use an anonymous function to pass parameters into the event...
Read more >
Pass arguments through event listeners - JavaScript Tutorial
You see, whenever you set up a new event listener and you have a callback function, the event object is automatically passed to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found