Winkel-5 Reaktiven Formen - Radio Button-Group

Ich habe 2 radio-buttons, ich bin mit der reaktiven Formen und ich habe die Formular-Steuerelemente innerhalb meiner Komponente. Das Problem, das ich bin vor ist, dass das name-Attribut muss gleich sein wie die formControlName. Wenn ich die name-Attribut als das gleiche, ich kann wählen Sie nur 1 radio button -- kann nie abzuwählen, und wählen Sie die andere. Nur erlaubt mir die Auswahl die gleiche.

this.genderControl = new FormControl("", Validators.required);

und dann Hinzugefügt, um meine Form Gruppe

genderControl: this.genderControl,

Mein HTML:

<div class="radio-inline">
  <input id="gender" type="radio" name="genderControl" formControlName="genderControl" />
  <label class="radio-label"> Male</label>
  <input id="gender" type="radio" name="genderControl" formControlName="genderControl" />
  <label class="radio-label">Female</label>
</div>

Form Gruppe

    this.personalInfo = new FormGroup({
  searchControl: this.searchControl,
  titleControl: this.titleControl,
  firstNameControl: this.firstNameControl,
  middleNameControl: this.middleNameControl,
  lastNameControl: this.lastNameControl,
  birthdayControl: this.birthdayControl,
  genderControl: this.genderControl,
  phoneControl: this.phoneControl,
  taxCanadaControl: this.taxCanadaControl,
  provinceControl: this.provinceControl,
  countryControl: this.countryControl,
  taxCountryControl: this.taxCountryControl,

  creditControl: this.creditControl
});
Können Sie nach wie haben Sie instanziieren Sie Ihr form von FormBuilder und auch Ihre html-Datei ?
Aktualisiert, die ich verwendet, FormGroup
Brauchen Sie dann wirklich ein name-Attribut?
Mögliche Duplikate von Radio-button formArray
Lassen Sie einfach die name Attribut.

InformationsquelleAutor Taranjit Kang | 2018-03-02

Schreibe einen Kommentar