I would like to create a directive that asks for confirmation when a user clicks on a button. To do that, I should be able to store the original event, and call it only when the user has confirmed his choice.
I have mocked a similar behavior here :
https://stackblitz.com/edit/angular-6wnvjk?file=src%2Fapp%2Fapp.component.html
(This is with a Timeout and not a confirmation, but the issue is the same)
How would one proceed to store the original event, then call it once the timeout/confirmation ends ?
import { Directive, ElementRef, HostListener } from '@angular/core';
@Directive({
selector: '[confirm]'
})
export class ConfirmDirective {
constructor() { }
@HostListener('click', ['$event'])
onClick(event: MouseEvent) {
console.log('handler from directive');
// 1 - Would like to store original event
const originalEvent = () => {};
// Would like to call it later
setTimeout(() => {
originalEvent();
})
}
}