mapConfig(config: IConfigItem[], dataModel: IDataModel): IConfigItem[] {
return config.map(c => {
const entries: [string, string][] = Object.entries(c);
entries.forEach(e => {
const configValue = e[0];
const configKey = e[1];
if (configKey in dataModel) {
c[configValue] = dataModel[configKey];
}
});
return { ...c };
});
}
I have this function in a service class , and i am calling this method from my angular component.
const configCopy = [...this.config];
const dataModelCopy = { ...this.dataModel };
const mappedConfig: IConfigItem[] = this.loader.mapConfig(
configCopy,
dataModelCopy
);
I am creating a copy of the this.config
object and passing it to the mapconfig
function so that it will not update the base object (this.config
), but its always updating the base object this.config
.Not sure if i am doing something wrong.