Reputation: 449
This is my select option HTML
<select _ngcontent-c3="" formcontrolname="role" value="" ng-reflect-name="role">
<option _ngcontent-c3="" value="addrole" ng-reflect-value="addrole">--Add Role--</option>
<option _ngcontent-c3="" value="64" ng-reflect-ng-value="64" description="user">EPS_USER</option>
<option _ngcontent-c3="" value="65" ng-reflect-ng-value="65" description="txns">TXNS</option>
</select>
I need to get selected option text value instead of its value, that is if I`m selecting EPS_USER, I should get "EPS_USER" instead of 64. Form has been implemented as reactive form.
this.form.controls["role"].value
This gives 64, how to get the text?
Upvotes: 1
Views: 1167
Reputation: 449
I have found a way around, passed $event object to the method and done this..
populateModule = (event) => {
let val = event.target.selectedOptions[0].innerHTML;
}
Upvotes: 1
Reputation: 512
Just add a attribute "label" in "option" with the value of your label and then do :
this.form.controls["role"].label
Upvotes: 1