【发布时间】:2021-06-18 13:48:48
【问题描述】:
情况
我有一张表,里面填满了来自接口 A 的数据。但是其中一列应该根据接口 A 的 id 填充接口 B 的过滤数据。
我尝试了什么
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);
})
}
问题
如果我运行应用程序,这些行将反复执行。如果我不想一遍又一遍地运行代码,我将如何解决这个问题?
编辑:尝试@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)=>{
【问题讨论】:
标签: angular typescript angular-material angular-services