Reputation:
I'm new to Angular, just a question on custom events. For normal event binding, we have the following code below:
<input class="form-control" (input)="selectedProduct=$event.target.value" />
but for custom bindings, I saw code like this:
<tr *ngFor="..." [pa-attr]="getProducts().length < 6 ? 'bg-success' : 'bg-warning'" (pa-category)="newProduct.category=$event">
so why it is not :
<tr ... (pa-category)="newProduct.category=$event.target.value">
Upvotes: 1
Views: 69
Reputation: 22213
Custom components emit the value which can be caught by $event
Suppose,
this is the custom component:
<input class="form-control" (input)="selectedProduct=$event.target.value" (blur)="onBlur()"/>
@Output() exampleOutput= new EventEmitter();
onBlur() {
exampleOutput.emit(selectedProduct)
}
Since exampleOutput
is emitting the value directly, when you use (exampleOutput)= "test = $event"
, test gets the value directly
Upvotes: 0