79475247

Date: 2025-02-28 10:46:46
Score: 1
Natty:
Report link

Below is what helped me reset my reactive form, with validations set to initial state after submission

 import { FormGroupDirective} from '@angular/forms';

  
 @ViewChild(FormGroupDirective) formGroupDirective!: FormGroupDirective;

// Add this after form submit
// To retain name value
const nameValue = this.form.get('name').value;
this.formGroupDirective.resetForm();
this.form.patchValue({ // Restore name value
  name: nameValue
});

Got this answer from this excellent youtube video - https://www.youtube.com/watch?v=V4FKf8JDkC8

Reasons:
  • Blacklisted phrase (1): youtube.com
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Zuhair