How can I get the selected option text on change function in Angular(TypeScript) ?
Asked
Active
Viewed 2,885 times
1
-
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 Answers
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
-
if i use option value this function(onChange) return value. but i need text . – Batuhan Batu Jan 25 '19 at 06:39
-