Hello everyone I have a problem when inserting the data I pick up from a rest service, this service would be like this.
valor: Object =
{
nombre: "jose",
apellido: "campos",
direccion: {
direccion: "calle de la mar",
numero: "18"
},
contactos: [
{
numero: "123454444",
tipo: "fijo"
},
{
numero: "44455533",
tipo: "fijo"
}
]
}
I set up the form as follows.
this.forma = new FormGroup({
'nombre': new FormControl(''),
'apellido': new FormControl(''),
'direccion': new FormGroup({
'direccion': new FormControl(''),
'numero': new FormControl('')
}),
'contactos': new FormArray([
new FormControl(''),
new FormControl('')
]),
});
Here is where I show the FormArray "contacts" that has a formGroup inside
<div formArrayName="contactos">
<div *ngFor="let item of forma.controls['contactos'].controls; let i=index" [formGroupName]="i">
<div class="form-group row">
<label class="col-2 col-form-label">Numero</label>
<div class="col-lg-8">
<input class="form-control" type="text" placeholder="Numero" formControlName="numero">
</div>
</div>
<div class="form-group row">
<label class="col-2 col-form-label">Tipo</label>
<div class="col-lg-8">
<input class="form-control" type="text" placeholder="Tipo" formControlName="tipo">
</div>
</div>
</div>
Everything loads well except "contacts", if I make a contact console.log or even if I submit, the data is loaded, but I can not get it reflected in the form input
Error: Cannot find control with path: 'contactos -> 0 -> numero'
This is the error that throws me, I infer that it is because it does not find the formControl "number" but I do not see where to put it because if I use
'contactos': new FormArray([
new FormGroup({
'numero': new FormControl(''),
'tipo': new FormControl('')
})
]),
I can not even upload the form, someone can give me a hand I've been several days and I can not see the solution.