I am trying to get the Text of Selected option of Select control in Angular 4.
HTML:
<div class="col-sm-6 form-group">
<label>Industry</label>
<select class="form-control select" formControlName="Industry">
<option value="">Please select Value</option>
<option *ngFor="let industry of industries"
[ngValue]="industry.ID">{{industry.Name}}
</option>
</select>
</div>
upload.component.ts
this.form.controls['Industry'].valueChanges.subscribe((name) => {
this.form.controls['IndustryName'].setValue(name);
});
I am using formControlName property from Reactive.
Kindly suggest the idea to retrive the Text of Selected Select control
You can use
<select class="form-control" (change)="onChange($event)">
</select>
then in the component
onChange($event){
let text = $event.target.options[$event.target.options.selectedIndex].text;
}
getSelectedOptionText(event: Event) {
let selectedOptions = event.target['options'];
let selectedIndex = selectedOptions.selectedIndex;
let selectElementText = selectedOptions[selectedIndex].text;
console.log(selectElementText)
}
HTML
<select class="form-control select" formControlName="Industry" (change)="getSelectedOptionText($event)">
<option value="">Please select Value</option>
<option *ngFor="let industry of industries" value="{{industry.ID}}">{{industry.Name}}</option>
</select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With