Home > front end >  Angular CTRL S to submit form
Angular CTRL S to submit form

Time:05-25

How can i add a global listener that invoke submit button in all application forms

when the user press ctrl s

CodePudding user response:

You can register following event globally. Based on what form you are currently on, trigger submitting ( formSubmit / trigger button click method )

    document.addEventListener('keydown', e => {
      if (e.ctrlKey && e.key === 's') {
        // Stop app to open save window
        e.preventDefault();
        console.log('CTRL   S Clicked');
        // do your form submission logic here
      }
    });

CodePudding user response:

@HostListener('document:keydown.control.s', ['$event']) onKeydownHandler(event: 
KeyboardEvent) {
   console.log('Submitted');
   event.preventDefault();
   // todo
}
  • Related