gpt4 book ai didi

Angular 4获取Select控件的Selected选项的文本

转载 作者:太空狗 更新时间:2023-10-29 17:17:07 25 4
gpt4 key购买 nike

我正在尝试获取 Angular 4 中 Select 控件的 Selected 选项的文本。

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);
});

我正在使用 Reactive 的 formControlName 属性。

请提出检索Selected Select控件Text的思路

最佳答案

你可以使用

<select class="form-control" (change)="onChange($event)">

</select>

然后在组件中

onChange($event){
let text = $event.target.options[$event.target.options.selectedIndex].text;
}

关于Angular 4获取Select控件的Selected选项的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47217734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com