user9623401
user9623401

Reputation:

why custom events do not need to be used with xxx.target.value"

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

Answers (1)

Adrita Sharma
Adrita Sharma

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

Related Questions