小编Pra*_*vin的帖子

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

我想在Angular 4中获取Select控件的选择文本选项.

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);
  });
Run Code Online (Sandbox Code Playgroud)

我正在使用Reactive的formControlName属性.

请建议回顾选定文本选择控件

angular angular-reactive-forms

8
推荐指数
4
解决办法
3万
查看次数

Angular 4 - 使用 FormControlName 访问 Typescript 中的 HTML 元素

我想使用 FormcontrolName 访问打字稿中的 HTML 元素。

我可以使用html元素 ID访问元素

例如 :

var element = document.getElementById("txtID")
Run Code Online (Sandbox Code Playgroud)

但是我们可以使用 FormControl 访问元素吗(不使用 ID)

typescript angular

1
推荐指数
1
解决办法
9652
查看次数