In an event binding, Angular configures an event handler for the target event. You can use event binding with your own custom events.
When the component or directive raises the event, the handler executes the template statement. The template statement performs an action in response to the event.
A common way to handle events is to pass the event object,
$event, to the method handling the event. The
$event object often contains information the method needs, such as a user's name or an image URL.
The target event determines the shape of the
$event object. If the target event is a native DOM element event, then
$event is a DOM event object, with properties such as
In the following example the code sets the
value property by binding to the
<input [value]="currentItem.name" (input)="currentItem.name=$event.target.value" > without NgModel
With this example, the following actions occur:
inputevent of the
<input>element, which allows the code to listen for changes.
$event.target.valueand updates the
If the event belongs to a directive or component,
$event has the shape that the directive or component produces.
© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.