I want to edit a data but I don't know how can I popule the form again with the json response from my API
In my response i get my json
project: {
"id": 1,
"customer": "Jhonathan",
"steps": "{"id":1,"paso":"Paso 1","accion":"accion 1","punto_critico":"punto critico 1","razon":"razon 1","fichero":"fileImage","namefile":"3.jpg"}",
"epp": "{"zapatos":"zapatos","guantes":"guantes","mandil":"mandil","lentes":"lentes","faja":"faja","chaleco":"chaleco","tapones":"tapones","mascarilla":"mascarilla","otro":""}",
"turns": "["2 Turno"]",
"created_at": "2021-01-13T15:20:49.000000Z",
"updated_at": "2021-01-15T02:20:33.000000Z",
"deleted_at": null
}
I've my form in this way
editProject = this.formBuilder.group({
id: [1],
customer: [''],
steps: this.formBuilder.array([this.newStep]),
epp: new FormGroup({
zapatos: new FormControl(''),
guantes: new FormControl(''),
mandil: new FormControl(''),
lentes: new FormControl(''),
faja: new FormControl(''),
chaleco: new FormControl(''),
tapones: new FormControl(''),
mascarilla: new FormControl(''),
otro: new FormControl(''),
}),
turns: [[]],
})
the form that i create the step array is with this
getNewId() {
this.currentStepId += 1;
return this.currentStepId;
}
get newStep(): FormGroup {
return this.formBuilder.group({
id: [this.getNewId()],
paso: ['Paso ' + this.currentStepId],
accion: [''],
punto_critico: [''],
razon: [''],
fichero: ['']
})
}
get steps(): FormArray {
return this.editProject.get('steps') as FormArray
}
Addsteps() {
this.steps.push(this.newStep);
}
Is my firts time trying to do this. I tray making like this but I think that i got a infinit loop because my app never stop charging and it crash
for(let line = 0; line < response.project.steps.length; line++){
const linesFormArray = this.editProject.get('steps') as FormArray;
linesFormArray.push(this.newStep);
}
hope someone can help me
question from:
https://stackoverflow.com/questions/65829732/populate-withjson-data-formarray-angular-11