Imagine a situation where a component called searchBox is given two inputs: @Input() titles: string[]
and @Input() model: Object
. The number of values in the titles array matches the number of properties in the model object. The searchBox component generates an input box for each item in the titles array, allowing users to enter search terms which are then stored in a string array named titlesValues. In order to properly link these values to the corresponding properties in the model object, the searchBox component needs to assign the values of titlesValues to the model properties one by one and output the updated model using @Output resultModel: Object
. I attempted to dynamically access each property of the model object for assignment as shown in the code snippet below:
let i =0;
Object.keys(this.model).forEach((key) => {
this.model[key] = this.titlesValues[i];
});
Even though I've tested multiple statements and alternative approaches to achieve the desired outcome, I encountered the following error:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'.
How should I go about implementing this scenario effectively? Thank you.