1

How can I get the selected option text on change function in Angular(TypeScript) ?

Batuhan Batu
  • 131
  • 1
  • 2
  • 9
  • please check this [question](https://stackoverflow.com/questions/35945001/binding-select-element-to-object-in-angular) I'm sure you will find you're answer there – Matan Shushan Jan 24 '19 at 10:27

1 Answers1

2

IF you use default select html you can try this: In youcomponent.html:

<select (change)="onChange($event.target.value)">
    <option>Test1</option>
    <option>Test2</option>
</select>

In you component.ts:

onChange(deviceValue) {
    console.log(deviceValue);
}

EDIT: To console text insted of value you must do this :

<select (change)="onChange($event)">
    <option [value]="1">Test1</option>
    <option [value]="2" >Test2</option>
</select>

And in your controller you must use :

  onChange(event) {
    console.log(event.target.options[event.target.options.selectedIndex].text);
}
Anton Skybun
  • 1,479
  • 8
  • 21