angular - Detect keyboard with HostListener -




i create few components in angular (4.0.0) detect keyboard language (rus-eng) decorator hostlistener:

// detect keyboard lan @hostlistener("window:keypress", ["$event"]) public detectkeyboard(keycode: number, mode: string): void {     // if current lan rus     if (mode === "rus") {         if (keycode >= 128 && keycode <= 255) {             this.currentkeyboard = "rus on";         } else {             this.currentkeyboard = "eng on";         }     } } 

and method interfacing keyboard message

// interfacing keyboard message public getkeyboard(): string {     return this.currentkeyboard; } 

this template:

<div *ngif="getkeyboard()" class="alert alert-danger">     {{currentkeyboard}} </div> 

and add output share in component:

@output("keyboard") public keyboard: eventemitter<object>; 

in template of component call this:

<div (keypress.keyboard)="detectkeyboard($event.keycode, 'rus')"> </div> 

and problem hostlitener decorator, can't call method detectkeyboard, , don't why. maybe problem parameters of hostlistener?





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -