Event Binding

An event handler is specified inside the template using round brackets to denote event binding. This event handler is then coded in the class to process the event.

Bind events to HTML elements

  • Bind to native events (such as click events):
    • <button (click)=”function”>
  • Bind to custom events we make
    • <app-home (update)=”function”></app-home>

—-HTML file

<button (click)="alertMe('I like beef')">Click Me</button>

—-TS File (Component)

alertMe(val){
   alert(val);
}

Leave a Reply

Your email address will not be published. Required fields are marked *