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
Post a Comment