我想在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属性.
请建议回顾选定文本选择控件
我想使用 FormcontrolName 访问打字稿中的 HTML 元素。
我可以使用html元素 ID访问元素
例如 :
var element = document.getElementById("txtID")
Run Code Online (Sandbox Code Playgroud)
但是我们可以使用 FormControl 访问元素吗(不使用 ID)