我正在使用Angular(6)渲染html表,并且从服务器接收到两个数据流:
this.columns = this.http.get('/api/columns');
this.rows = this.http.get('/api/rows');
就这个问题而言,让我们说一下,两个api调用都返回一个包含以下对象的数组:
{
"name": "value",
"key": "[key which joins the columns and rows]"
}
和我的模板:
<tr *ngFor="let row of (rows | async)">
<td *ngFor="let column of (columns | async)">{{ (join(row, column)| async).name }}</td>
</tr>
您可以看到它通过调用join方法通过键连接:
join(row, column) : Observable<string> {
return this.colums.pipe(
single((c: columns) => {
return c.key === row.key;
}),
map((c: column) => {
return c.name;
})
)
}
我的问题是,在渲染数据时,Observable会持续解析每一行和每一列。因此,每个循环周期都会调用api。我不知道为什么我给人的印象是,当异步管道解决一次后,它将循环遍历该集合。