I am developing an application, in Angular 15, that displays a form for a dynamic query. I get the form parameters from the Backend. I get from back something like this
{
"codRespuesta": 0,
"glosaRespuesta": "Ejecución Exitosa",
"paramReportList": [
{
"codEmpresa": 1,
"idReport": 1,
"idParamReport": 1,
"nomParamReport": "sucursal",
"tipoDato": "SUCURSAL"
},
{
"codEmpresa": 1,
"idReport": 1,
"idParamReport": 1,
"nomParamReport": "id_usuario",
"tipoDato": "NUMBER"
},
{
"codEmpresa": 1,
"idReport": 1,
"idParamReport": 2,
"nomParamReport": "fechaTermino",
"tipoDato": "Date"
}
]
}
where TipoDato says which type of input I have to show in the form.
For displaying the form, I made a FormGroup to add the new elements to the form.}
this.queryForm = this.fbuilder.group({});
Therefore, I evaluate each parameter I receive back using this function
evalParam(tipo: string, nomParam: string) {
const tipoEval = tipo.toUpperCase();
switch (tipoEval) {
case 'SUCURSAL':
this.isSucursal(nomParam);
break;
case 'NUMBER':
this.isNumber(nomParam);
break;
case 'VARCHAR':
this.isVarchar(nomParam);
break;
case 'DATE':
this.isDate(nomParam)
break;
default:
break;
}
}
Where in case of isNumber, I add a new FormControl with the name of the parameter and I display using Rendered2 the new element in the form
isNumber(nomParam: string) {
this.renderInput('nomPdd', 'number')
this.queryForm.addControl(
nomParam,
new FormControl('', [Validators.required])
);
}
renderInput(nomParam: string, type: string) {
const input = this.renderer.createElement('input')
this.renderer.setAttribute(input, 'type', type);
this.renderer.addClass(input, 'input-reporte');
this.renderer.setAttribute(input, 'formControlName', nomParam);
const label = this.renderer.createElement('label');
const labelText = this.renderer.createText(nomParam);
this.renderer.appendChild(label, labelText);
const div = this.renderer.createElement('div');
this.renderer.addClass(div, 'my-3');
this.renderer.appendChild(div, label);
this.renderer.appendChild(div, input);
this.renderer.appendChild(this.formulario.nativeElement, div);
}
The problem is when I try to submit the form data, and the value of each element of queryForm is empty.
Please, if anyone can help me, I will be very grateful