Skip to content

Instantly share code, notes, and snippets.

@shafiqshams
Created February 22, 2018 20:22
Show Gist options
  • Save shafiqshams/225c5fd6ef4f9ed29199f92855aa07c8 to your computer and use it in GitHub Desktop.
Save shafiqshams/225c5fd6ef4f9ed29199f92855aa07c8 to your computer and use it in GitHub Desktop.
Keyboard Events Ionic 2
import { Component } from '@angular/core';
@Component({
selector:'sandbox',
template:`
<h1>Hello World</h1>
<div>
<input type="text" (keyup)="fireEvent($event)" placeholder="keyup event">
</div>
<div>
<input type="text" (keydown)="fireEvent($event)" placeholder="keydown">
</div>
<div>
<input type="text" (focus)="fireEvent($event)" placeholder="focus">
</div>
<div>
<input type="text" (blur)="fireEvent($event)" placeholder="blur">
</div>
<div>
<input type="text" (cut)="fireEvent($event)" placeholder="cut">
</div>
<div>
<input type="text" (copy)="fireEvent($event)" placeholder="copy">
</div>
<div>
<input type="text" (paste)="fireEvent($event)" placeholder="paste">
</div>
<hr>
<div>
<input type="text" (keyup)="changeText($event)" placeholder="change text" value={{text}}>
</div>
<h2>{{ text }}</h2>
`
})
export class SandboxComponent{
text:string = 'Hello';
fireEvent(e){
console.log(e.type);
}
changeText(e){
this.text = e.target.value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment