Is it possible to create a directive that prompts for confirmation when a button is clicked? This would involve storing the original event and only executing it once the user confirms their choice.
A similar behavior has been mocked here:
https://stackblitz.com/edit/angular-6wnvjk?file=src%2Fapp%2Fapp.component.html
(Although this example uses a Timeout instead of confirmation, the concept remains the same)
What approach should be taken to save the original event and then trigger it after the timeout/confirmation process is completed?
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();
})
}
}