2017-11-20 17 views
1

データベースに保存されているユーザーの性別を取得するためのフォームを作成しました。ジェンダーはradioButtonとして送信されます。値はデータベースに正しく送られ、私はそれをも取り出すことができます。対応するラジオボタンをチェックするだけです。これは私の.htmlコードです。私.tsファイルでデータバインディングAPI付きラジオボタン

<div class="form-group col-lg-6" ngbRadioGroup> 
      <!-- Gender --> 
      <label for="">Gender</label> 
      <label ngbButtonLabel class="btn-primary customButtons" > 
      <input ngbButton type="radio" value="male" formControlName="gender"> Male 
      </label> 
      <label ngbButtonLabel class="btn-primary customButtons"> 
      <input ngbButton type="radio" value="female" formControlName="gender" >Female 
      </label> 
      </div> 

、私は通常、次のように入力し、入力がテキストボックスだった場合、それは動作します:事前に

this.form.controls['gender'].setValue(this.influencer.gender); 

感謝。ドキュメントの

答えて

0

同様に:

<div class="form-group col-lg-6" ngbRadioGroup formControlName="gender"> 
    <!-- Gender --> 
    <label for="">Gender</label> 
    <label ngbButtonLabel class="btn-primary customButtons" > 
    <input ngbButton type="radio" value="male"> Male 
    </label> 
    <label ngbButtonLabel class="btn-primary customButtons"> 
    <input ngbButton type="radio" value="female">Female 
    </label> 
</div> 
https://ng-bootstrap.github.io/#/components/buttons/examples

formControlName代わりに、各個々のラジオボタンを、ngbRadioGroupが使用されている要素に設定され、そうするようにコードを変更します

関連する問題