DEV Community

Discussion on: Using a Promise in a click eventListener - more than once.

Collapse
 
copperwall profile image
Chris Opperwall

I might be wrong, but I think one way would be to pass a callback into returnCollectionsId and then call that callback from inside returnCollectionsId from the click event handler you set up. Then anytime element1 is clicked, your callback will be called, instead of just the first time.

If you wanted to use Observables I think you could use Rx.js without angular. Instead of returning a promise that sets up an on click handler and resolves when the onClick is called for the first time, you can return an Observable and subscribe to it in whatever code calls returnCollectionsId.

Here's a blog post about setting up Rx.js with click events from a few years ago codyburleson.com/respond-to-button...

Thread Thread
 
alittlebyte profile image
Vlad • Edited

Thank you, I've tried both. The way I made everything, it doesn't want to wait for anything else but a Promise, unfortunately. Still launches immediately. Or I need a couple more days for the new information to sink in, and then I'll figure out how to get it to work. Will see, thank you again!