I would like to set up an event listener in a component on keydown event in Ember. The event listener gets properly added, but I can't seem to remove it as the removeEventListener passes in a different function. Any help on how to properly set this up would be appreciated.
onEscPress(e) {
if (e.which === 27) {
alert('test');
this.send('dismissModal');
}
},
willInsertElement() {
window.addEventListener('keydown', this.onEscPress(e), false);
},
willDestroyElement() {
// Uses a different function, so doesn't properly remove the listener
window.removeEventListener('keydown', this.onEscPress(e), false);
},
Aucun commentaire:
Enregistrer un commentaire