Skip to main content

Posts

Showing posts with the label Event Handlers

How to bind to user input events to component event handlers?

Most of the DOM events are triggered by user input and bind to these events provides a way to get inputs from a user. The following example shows a click event binding – [on-click.component.ts] import  {  Component ,  OnInit  }  from   '@angular/core' ; @ Component ({    selector:   'app-on-click' ,    templateUrl:   './on-click.component.html' ,    styleUrls:  [ './on-click.component.css' ] }) export   class   OnClickComponent   implements   OnInit  {    welcomeMsg  =  '' ;    constructor () { }    ngOnInit () { }    onClick () {      this . welcomeMsg  =  'Welcome you, Anil!' ;    } } And on-click.component.html - < div   class = "msg" >    < button  ( click )= "onClick()" >C lick Me! </ button >   ...