Actions of Event Binding

Actions of Event Binding - Angular 4

In an event binding, Angular sets up an event handler for the target event.

Example looks like -
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'on-click',
  template: `<div>
        <div><button (click)="onClick($event)"> keyup here.</button> <p>{{message}}</p></div>
        <div><input (keyup)="onKey($event)"> <p>{{values}}</p></div>  </div>`
})
export class clickComponent {
  values = '';

  onClick(event) {
    console.log(event);
  }

  onKey(event: any) {
    //without type info
    this.values += event.target.value + ' | ';
  }
}

Example 2 – dblclick keypress
import { ComponentOnInit } from '@angular/core';

@Component({
  selector: 'on-click',
  template: '<div> <button (keypress)="OnKeypress()"> keypress here.</button>{{message}} </div>'
})
export class KeypressComponent {
  message = "";

  OnKeypress() {
    this.message = 'Hey, How are You?';
  }
}

I hope you are enjoying with this post! Please share with you friends. Thank you!!
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^