Sorry if the title is confusing, not sure how to word it. I am trying to call a function to get data and pass it to a child component.
parent.component.ts:
getData(arg: string[]) {
let data: any[];
// Do stuff here to get data
return data;
}
parent.component.html:
<app-child [myData]="getData(['test'])"></app-child>
child.component.ts
export class ChildComponent {
@Input() myData: any[];
// Stuff here
}
child.component.html
<h3>{{ myData[0].test }}</h3>
However, when I run the application, I get an error saying that it Cannot read property '0' of undefined. What am I doing wrong? I don't want to create a variable to bind to [myData] because I would then have a lot of them. I will be using this function in other places as well.
Any help would be appreciated, thank you!