How can I listen for keypress event on the whole page?
I would use @HostListener decorator within your component: import { HostListener } from ‘@angular/core’; @Component({ … }) export class AppComponent { @HostListener(‘document:keypress’, [‘$event’]) handleKeyboardEvent(event: KeyboardEvent) { this.key = event.key; } } There are also other options like: host property within @Component decorator Angular recommends using @HostListener decorator over host property https://angular.io/guide/styleguide#style-06-03 @Component({ … host: { … Read more