Skip to content

Commit 62e1f3c

Browse files
authored
Merge pull request #1 from fnimick/master
Fix TypeError when keyCode is undefined (e.g. during autofill)
2 parents 91f678d + 71671cf commit 62e1f3c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/konami.directive.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ export class KonamiDirective {
1414

1515
@HostListener('document:keydown', ['$event'])
1616
handleKeyboardEvent(event: KeyboardEvent) {
17-
this.sequence.push(event.keyCode.toString());
17+
if (event.keyCode) {
18+
this.sequence.push(event.keyCode.toString());
1819

19-
if (this.sequence.length > this.konamiCode.length) {
20-
this.sequence.shift();
21-
}
20+
if (this.sequence.length > this.konamiCode.length) {
21+
this.sequence.shift();
22+
}
2223

23-
if (this.isKonamiCode()) {
24-
this.konami.emit();
24+
if (this.isKonamiCode()) {
25+
this.konami.emit();
26+
}
2527
}
2628
}
2729

0 commit comments

Comments
 (0)