I've been working on creating a Typescript function that returns an object, but I keep encountering the following error message:
ERROR in src\app\components\model\model.component.html(3,30): : Property 'heading' does not exist on type '{}'.
Here is my function:
getTestObject(): { [key: string]: any } {
let myObj = {};
myObj = {
'heading': 'My heading',
/* Other properties here */
};
return myObj;
}
In my HTML file, I try to use it like this: {{ myObj.heading }}
. After reading some advice on Typescript property does not exist on type {}, I made the following change:
let myObj = {};
changed to:
let myObj = {} as { [key: string]: any };
despite making this adjustment, I am still facing the same error. Where am I going wrong? Your assistance would be greatly appreciated. Thank you!