Answers for "angular reactive form radio button checked"

0

reactive forms radio button

<form [formGroup]="form">
   <label>
     <input type="radio" value="Male" formControlName="gender">
       <span>male</span>
   </label>
   <label>
     <input type="radio" value="Female" formControlName="gender">
       <span>female</span>
   </label>
</form>
Posted by: Guest on May-03-2020
1

angular 2 reactive forms radio button by default checked

HTML file:

<form [formGroup]="form" (ngSubmit)="onSubmit()">
  <input type="radio" formControlName="skill" [value]="skillsForBackend[0]">
  <input type="radio" formControlName="skill" [value]="skillsForBackend[1]">
</form>


TS file:
ngOnInit() {
  this.form = this.fb.group({
    skill: [this.skillsForBackend[0], Validators.required]
  });
}

onSubmit() {
  console.log(this.form.value) // should show { skill: /* your data */ }
}
Posted by: Guest on April-04-2022

Code answers related to "angular reactive form radio button checked"

Browse Popular Code Answers by Language