我想用一个收音机按钮
formControl
以下内容:
constructor(private rest: RestClient, private fb: FormBuilder) {
this.mySearchform = this.fb.group({
searchType: '', searchTypeValue: ''
});
}
在这里
searchType
是一个单选按钮组,并且
searchTypeValue
是文本字段。
在我的HTML中,我有:
<div class="form-row">
<div class="form-group col-2">
<label for="one" class="col-form-label">
<input type="radio" [value]="oneValue" id="one" formControlName="searchType"/>
CustomerId
</label>
</div>
<div class="form-group col-2">
<label for="two" class="col-form-label">
<input type="radio" [value]="twoValue" id="two" formControlName="searchType"/>
AccountNumber
</label>
</div>
<div class="form-group col-2">
<label for="three" class="col-form-label">
<input type="radio" [value]="threeValue" id="three" formControlName="searchType"/>
Email
</label>
</div>
<div class="form-group col-6">
<input id="searchTypeValue" formControlName="searchTypeValue" class="form-control" />
</div>
</div>
我试图将该值理解为:
this.mySearchform.get('searchType').value
我的单选按钮组工作不正常。在选择它们中的任何一个时,所有三个都将被选中。
我错过了什么或做错了什么?