Home > Software engineering >  Angular force form validation on load with Material form controls
Angular force form validation on load with Material form controls

Time:01-30

I need the form validation to show up when the form loads. The problem is the only way I've been able to get it to show up for a mat-radio-group is to call form.markAllAsTouched(). But on the initial load (a user coming back to the form) there isn't a hook I can find to latch onto where I can call that method. I've tried ngAfterViewChecked(), but it throwing errors.

CodePudding user response:

try to do the following immediately after create the form:

this.sampleForm = this.formBuilder...

setTimeout(()=>{
   this.sampleForm.patchValue(this.myForm.value)
})
  •  Tags:  
  • Related