0

I'm having this error:

ERROR Error: Must supply a value for form control at index: 1.

I'm doing an app with Angular 9, the problem is at Typescript.

The following code is working:

this.registros.controls.arrayProcedimientos.setValue(convert.arrayProcedimientos);

But if I sort the array and then do a setValue I don't know what happens but is not working, example:

convert.arrayProcedimientos.sort(function(a,b){
          return a.fechaInicioProcedimiento > b.fechaInicioProcedimiento;
        });

//setValue of the sorted array
this.registros.controls.arrayProcedimientos.setValue(convert.arrayProcedimientos);

psd: I tried doing a patchValue(), which it doesn't throw an error, but the problem is that the object is an array of arrays. So doing a patchValue works nice on the unique fields but on the subarrays is trolling (literally).

Thanks for your attention and help, and if you need some pictures or whatever feel free to ask.

Great community :)

1 Answer 1

1

I think first you need to fix they way you are sorting, not sure how its working for you. It must give you compile time error at sorting.

Instead of this

convert.arrayProcedimientos.sort(function(a,b){
          return a.fechaInicioProcedimiento > b.fechaInicioProcedimiento;
     });

Use this

 convert.arrayProcedimientos.sort(function(a,b){
              return a.fechaInicioProcedimiento - b.fechaInicioProcedimiento;
         });

And then

this.registros.controls.arrayProcedimientos.setValue(convert.arrayProcedimientos);

should work.

Here is why I am asking you to change the sorting syntax TypeScript sorting an array

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for your response. It was not exactly the answer. I found my problem. And the problem is that I was "preparing memory before the values" so that's the reasson that I was retrieving the error. Anyway thanks for yout time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.