diff --git a/packages/core/src/metadata/directives.ts b/packages/core/src/metadata/directives.ts index e29149856a..08646edc27 100644 --- a/packages/core/src/metadata/directives.ts +++ b/packages/core/src/metadata/directives.ts @@ -872,6 +872,29 @@ export interface HostListener { * template: '', * }) * class App {} + * + * ``` + * + * The following example registers another DOM event handler that listens for key-press events. + * ``` ts + * import { HostListener, Component } from "@angular/core"; + * + * @Component({ + * selector: 'app', + * template: `

Hello, you have pressed keys {{counter}} number of times!

Press any key to + * increment the counter. + * ` + * }) + * class AppComponent { + * counter = 0; + * @HostListener('window:keydown', ['$event']) + * handleKeyDown(event: KeyboardEvent) { + * this.counter++; + * } + * resetCounter() { + * this.counter = 0; + * } + * } * ``` * * @Annotation