简体   繁体   中英

angular material radio buttons default selected not validating the form

My project is in Angular 9 and I am using reactive forms, I have Angular Material Radio buttons group (mat-radio-button) in my form, I have default value checked, and the Radio control is not required in my form, as I have a default value selected. now my form validate the radio buttons I have to select one option, any idea why my form is invalid if I don't select a radio option, my save button keeps disabled.

component.ts

      this.myform= this._formBuilder.group({
  TaskName: ['', Validators.required],
  Schedule: ['', null],

});

component.html:

  <mat-radio-group aria-labelledby="theschedule" formControlName="Schedule" >
     <mat-radio-button (change)="radioChange($event);"  id="{{item.Name}}"  *ngFor="let item of sType" [value]="item.ID" [checked]="item.ID === 1" >
                                {{item.Name}} 
     </mat-radio-button>
  </mat-radio-group>

 <button mat-raised-button color="primary" type="submit" [disabled]="!myform.form.valid" >Save</button>

I think it should be [disabled]=".myForm.valid" instead of [disabled]=".myform.form.valid"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM