Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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 */ }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #angular #reactive #forms #radio #button #default #checked
ADD COMMENT
Topic
Name
8+9 =