Issue arises when attempting to access map keys or values using a method, resulting in the following error:
ERROR TypeError: factors.values is not a function or its return value is not iterable
These model interfaces are used for object types:
export interface Plant{
name: string;
templateName: string;
}
export interface RiskFactor {
riskId: number;
name: string;
slotName: string;
factorType: string;
plantType: string;
}
export interface Symptom {
symptomId: number;
name: string;
slotName: string;
plantType: string;
checked: boolean;
}
export interface DiagnoseForm {
riskFactors: Map<string, RiskFactor[]>;
symptoms: Symptom[];
}
The server response is saved in the "formData" variable with DiagnoseForm, allowing normal access and creation of formArray from symptoms:
buildSymptoms(){
const arr = this.formData.symptoms.map(symptom => {
symptom.checked = false;
return this.formBuilder.control(false);
});
return this.formBuilder.array(arr);
}
Error occurs when trying to retrieve the riskFactors arrays from the map leading to the above-mentioned issue in the following code:
buildRiskFactors(){
const factors: Map<string, RiskFactor[]> = this.formData.riskFactors;
for( let wrapper of factors.values()){
console.log(wrapper);
}
}
Various attempts have been made to resolve this problem but all efforts result in the same output.