Vương Hữu Thiện
Vương Hữu Thiện

Reputation: 1710

ERROR Error: this.validator is not a function

I get this error after creating FormGroup.

image of the error

I created a simple error template on Stackblitz.

My sample data is as follows:

enter image description here

Create a FormGroup as shown below:

enter image description here

I understand that it is not possible to create FormGroup of a string array. Because the data does not have a key value to create a name for the form group.

Is there a way to deal with this?

Upvotes: 0

Views: 420

Answers (1)

Chellappan வ
Chellappan வ

Reputation: 27293

You can tranform arr_obj and arr_str into formArray using map operator something like this:

   const formConfig = this.data.map((item)=>{
      if(item.arr_obj || item.arr_str){
        return {...item,arr_obj: this.fb.group(item.arr_obj),arr_str: this.fb.array(item.arr_str)}
      } 
      return item;
    });

    formConfig.forEach(item => {
      var temp = this.fb.group(item);
      console.log(temp);
    });

Upvotes: 1

Related Questions