Reputation: 608
When I try submit form and when I console.log()
it only appear null without value.
This my demo code and stackblitz
HTML
<form [formGroup]="changeNotifyForm" (ngSubmit)="onSubmit()">
<mat-radio-group class="example-radio-group" name="favoriteSeason" [(ngModel)]="favoriteSeason" [ngModelOptions]="{standalone: true}">
<mat-radio-button class="example-radio-button" *ngFor="let season of seasons" [value]="season">
{{season}}
</mat-radio-button>
</mat-radio-group>
<button>submit</button>
</form>
Component
changeNotifyForm:FormGroup;
constructor(private fb: FormBuilder){
this.changeNotifyForm = fb.group({
notify: ['', Validators.required]
});
}
onSubmit() {
const notifys = this.changeNotifyForm.value;
console.log(notifys)
}
Upvotes: 0
Views: 2108
Reputation: 8301
You do not need to use ngModel as you are already using reactive form. You just need to bind the formControl instance in component class with template using formControlName
.
<mat-radio-group class="example-radio-group" name="favoriteSeason" formControlName="notify">
Please find working code here: https://stackblitz.com/edit/angular-fhh6pp-nzroy9
Upvotes: 4