I am trying to create a Typescript function that returns an object. However, I keep getting the following error:
ERROR in src\app\components\model\model.component.html(3,30): : Property 'heading' does not exist on type '{}'.
My function looks like this:
getTestObject(): { [key: string]: any } {
let myObj = {};
myObj = {
'heading': 'My heading',
/* Other properties here */
};
return myObj;
}
Then I use it in my html file like this: {{ myObj.heading }}
. I was reading the answer over here: Typescript property does not exist on type {} and changed the following line:
let myObj = {};
changed to:
let myObj = {} as { [key: string]: any };
but I get the same error. What am I doing wrong? Any help would be appreciated, thank you!