If you want to perform any event on any specific keyboard button press, in that case, you can use @HostListener. For this, you have to import HostListener in your component ts file. I can use the following function to perform delete keyboard press.
import { HostListener } from '@angular/core';
then use below function anywhere in your component ts file.
@HostListener('document:keyup', ['$event'])
handleDeleteKeyboardEvent(event: KeyboardEvent) {
if(event.key === 'Delete')
{
// remove something... or call remove funtion this.remove();
}
}
remove(){
// code..
}