We have 2 arrays Speisekarte and Essensplan - I want to call the method printName, to print out the name, I get from the ID.
The problem is, "name" is always undefined.
"ERROR TypeError: Cannot read property 'name' of undefined"
How can i fix async in methods in templates?
Template (Async in printName(essenName) )
<div *ngFor="let i of essensplan"> <br />
<div><b>Woche : {{i.id}}</b></div> <br />
<button *ngFor="let id of i.essenProWoche" (click)="print(id)">Gericht
** {{printName(id)}} ** </button>
Component
ngOnInit() {
console.log("ngOnInite essensplan.component")
this.getSpeisekarte();
this.getEssensplan();
}
printName(id: number) {
this.essenName = this.speisekarte.find(i => i.id == id ).name
getSpeisekarte(): void {
this.essenService.getSpeisekarte()
.subscribe(speisekarte => this.speisekarte = speisekarte);
}
getEssensplan(): void {
this.essensplanService.getEssensplan()
.subscribe(essensplan => this.essensplan = essensplan)
}