const ESCAPE_KEYCODE = 27; @HostListener('document:keydown', ['$event']) onKeydownHandler(event: KeyboardEvent) { if (event.keyCode === ESCAPE_KEYCODE) { // ... } }