代码之家  ›  专栏  ›  技术社区  ›  Vicky

收音机按钮在角度5不工作

  •  1
  • Vicky  · 技术社区  · 7 年前

    我想用一个收音机按钮 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
    

    我的单选按钮组工作不正常。在选择它们中的任何一个时,所有三个都将被选中。

    我错过了什么或做错了什么?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Sajeetharan    7 年前

    value 而不是 [value]

    <label for="one" class="col-form-label">
                <input type="radio" value="oneValue" id="one" formControlName="searchType"/>
                CustomerId
    </label>
    
    推荐文章