Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typescript event emitter

//method 1
<input (keyup)="onKey($event)">

Email: <p>{{email}}</p>

//ts
export class AppComponent { 
  email: String = '';
  
  onKey(event: KeyboardEvent) { 
    this.email = event.target['value'];
    console.log("event", event);
  }
}           


	//method 2
  <input (keyup)="onKey($event)" (keypress)="onKey($event)" (keydown)="onKey($event)" >

	export class AppComponent {

  	onKey(event: KeyboardEvent) {
    console.log("This is", event.type);
  	}
   }   

  
  //method 3
  
  @HostListener("window:keypress", ["$event"])
    handleKeyboardEvent(event: KeyboardEvent) {
      console.log(event);
  }
Source by stacksjar.com #
 
PREVIOUS NEXT
Tagged: #typescript #event #emitter
ADD COMMENT
Topic
Name
2+3 =