Home > other >  FormArray in Angular TypeError value.forEach
FormArray in Angular TypeError value.forEach

Time:12-09

i have my FormService

    title: this.fb.group({
    titleList: this.fb.array([]),
    name: ['', [Validators.requiredValidator()]]
    }),

i add dynamic in my list with button new names

my Testing Class code

  const mock = { title: {
  titleList: new FormArray([]),
  name: 'Movie one',
  }}

  formService.get().setValue(mock);

my mock have another form elements - i cut it for this part i get the error: Failed: value.forEach is not a function, TypeError: value.forEach is not a function

CodePudding user response:

 const mock = { title: {
  titleList: [],
  name: 'Movie one',
  }}

  formService.get().setValue(mock);

You set a value, you don't create a new form.

  • Related