Sometimes, we want to get new selection in select in Angular.
In this article, we’ll look at how to get new selection in select in Angular.
How to get new selection in select in Angular?
To get new selection in select in Angular, we can watch the change
event.
For instance, we write
<select (change)="onChange($event.target.value)">
<option *ngFor="let i of devices">{{ i }}</option>
</select>
to add a select drop down.
Then in our component, we write
//...
export class Component {
constructor() {}
//...
onChange(deviceValue) {
console.log(deviceValue);
}
}
to add the onChange
method, which runs when we change selection since we have
(change)="onChange($event.target.value)
in the select.
Then we get the selected value from the parameter.
Conclusion
To get new selection in select in Angular, we can watch the change
event.