Issue
How can i add a global listener that invoke submit button in all application forms
When the user press ctrl+s
I Use Template forms and all the froms are ngForm
I Want to realize something like this: (without jQuery)
$("#container form").submit();
Solution
It work for me :
@Directive({
selector: 'form'
})
export class SaveCtrlSDirective {
constructor(private ngForm: NgForm) {
}
@HostListener('document:keydown.control.s', ['$event'])
onKeydownHandler(event:KeyboardEvent) {
event.preventDefault();
(this.ngForm as {submitted: boolean}).submitted = true;
this.ngForm.ngSubmit.emit(this.ngForm);
}
}
Answered By - Stack Overflow
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.