Situation
I have a table filled with data from interface A. But one of the columns should be filled with filtered data of interface B based on id of interface A.
What I tried
html:
<mat-table [dataSource]="dataSource">
...
<ng-container matColumnDef="title">
<mat-header-cell *matHeaderCellDef> Title</mat-header-cell>
<mat-cell *matCellDef="let element"> {{getValueOfInterfaceB(element.id)}} </mat-cell>
</ng-container>
...
</mat-table>
ts:
getValueOfInterfaceB(id: number){
let filter: any = {Id: id}
this.entrieService.getEntries(filter).subscribe((entries: Entry[]) => {
console.log(entries);
})
}
Problem
If I run the application these lines will be executed over and over. How would I solve this if I do not want to run the code over and over?
Edit: Errors getting while trying solution of @Eliseo
error TS2304: Cannot find name 'res'.
res[] => {
error TS1011: An element access expression should take an argument.
res[] => {
error TS1005: ',' expected.
res[] => {
error TS18004: No value exists in scope for the shorthand property 'res'. Either declare one or provide an initializer.
res.forEach((value,index)=>{
error TS2769: No overload matches this call.
res.forEach((value,index)=>{