I am unable to reset particular form fields in angular. I am attaching here link, where I am trying to achieve, but not working. Please help!!
- April 11, 2023
- 211 views
- 0 votes
- 2 Answers
-
I am unable to reset particular form fields in angular. I am attaching here link, where I am trying to achieve, but not working. Please help!!
2
Answers
I believe the problem here is a misunderstanding of how to use the AbstractControl.reset() method. The value parameter is not related to the controls you want to reset, but the values you want to reset the controls to.
If you change your method to:
It should work as expected!
Answered it in wrong question (wrong window). Since the solution is not same I am sharing it here.
Instead of index "i" send controls "o" in
resetContact
Then change the
resetContact()
function as below:To reset only phone field of a particular control you can use:
Working demo:
https://angular-dynamic-form-fields-cpoqww.stackblitz.io/
Editor URL:
https://stackblitz.com/edit/angular-dynamic-form-fields-cckshh?file=src/app/app.component.ts