Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Model-Driven form.reset() doesn't reset FormArray property

I have an angular 2 model driven form that has a property of type FormArray. When I call the myForm.reset(this._originalValue) method, the number of items in the FormArray is not reset to the original value.

Here is a plunker showing the problem: https://plnkr.co/edit/gRHD5Ikbm1aGzFQUF2nn?p=preview

Is there a way to force the myForm.reset() method to reset the count of items in properties of type FormArray? Or do I have to manually reset it?

like image 322
Amanda Kitson Avatar asked Dec 02 '16 15:12

Amanda Kitson


People also ask

How do I reset my FormArray value?

The proper way of resetting a form is by calling the reset() method on your templateForm property. Resets the FormGroup, marks all descendants are marked pristine and untouched, and the value of all descendants to null.

How reset Angular form and set default values after submitting?

In a model-driven form to reset the form we just need to call the function reset() on our myform model. The form now resets, all the input fields go back to their initial state and any valid , touched or dirty properties are also reset to their starting values.

How do you reset a form after submit in Angular?

import { FormsModule } from '@angular/forms'; In Reactive forms, we need to import FormGroup from '@angular/forms' . After importing the above-mentioned modules in the respective approach, angular forms module provides an inbuilt method called reset(). We can use the method and we can reset the form.

What does FormControl Reset do?

reset()linkResets the form control, marking it pristine and untouched , and resetting the value. The new value will be the provided value (if passed), null , or the initial value if nonNullable was set in the constructor via FormControlOptions .


1 Answers

Well, it appears this is a known issue and the Angular team has decided that folks will have to manually reset the FormArray size.

https://github.com/angular/angular/issues/10960

like image 130
Amanda Kitson Avatar answered Oct 13 '22 11:10

Amanda Kitson