Angular Error: Property 'Controls' does not exist on type 'Abstractcontrol'

Asked

Viewed 587 times

-1

I’m having trouble setting values within form inputs.

My form.component.ts:

    // Form
            this.constituicaoForm = this.fb.group({
                // Contrato
                descricao: ['', Validators.required],
                modalidade: ['', Validators.required],
                ...

                // Operações
                operacoes: this.fb.array([
                    this.fb.group({
                        tipoPessoa: ['', Validators.required],
                        numeroDocumento: ['', Validators.required],
                        ...
                    })
                ]),

                // Ativos
                ativos: this.fb.array([
                    this.fb.group({
                        tipoAtivo: ['', Validators.required],
                        idAtivo: ['', Validators.required],
                        ...
                    })
                ])
            });

When I try to enter a value in this.constitution it usually works using this code:

this.constituicaoForm.controls.tipoAtivo.setValue("tipoTeste");

But when I try to insert a value into operations or assets, in this way:

this.constituicaoForm.controls.ativos[0].controls.descricao.setValue("teste");

I get this error in the browser console (Chrome):

ERROR Typeerror: Cannot read Property 'Controls' of Undefined at Safesubscriber. _next (edit-record.component.ts:199) At Safesubscriber. __tryOrUnsub (Subscriber.js:185) at Safesubscriber.next (Subscriber.js:124) At Subscriber. _next (Subscriber.js:72) At Subscriber.next (Subscriber.js:49) at Mapsubscriber. _next (map.js:35) At Mapsubscriber.next (Subscriber.js:49) at Filtersubscriber. _next (filter.js:33) At Filtersubscriber.next (Subscriber.js:49) At Mergemapsubscriber.notifyNext (mergeMap.js:69)

And in the terminal I get this error:

ERROR in src/app/layout/content/records/edit-record/edit-record.component.ts(198,53): error TS2339: Property 'Controls' does not exist on type 'Abstractcontrol'.

1 answer

0

There is nothing in Indice 0 so from Undefined, to enter a new value do so:

this.constituicaoForm.get('tipoAtivo').push("tipoTeste");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.