我正在为在餐馆工作的人开发一个应用程序,我有一个仪表板,我可以在其中向他们展示一些关于他们预订的统计数据,其中有一部分显示了在给定时间段内预订最多的 5 位客户。
我向我的 *ngFor 发送了一个包含 5 个客户端的数组,但没有一个显示。
我 typescript 的一部分:
for (let i = 0; i < topClient.length; i++) {
this.clientService.retrieve(topClient[i]).subscribe(res => {
this.topUsers.push(res.body);
});
}
我的 HTML:
<div class="flex flex w-full" *ngFor="let client of topUsers">
<p class="w-64">{{ client.last_name }} {{ client.first_name }}</p>
</div>
我希望输出是我的 5 个客户端的列表,因为我知道 console.log(this.topUsers) 正在返回预期的 5 个客户端。
感谢您的帮助:')
编辑:这是 TopUsers 的 console.log 和 Tony 更改后的控制台错误: 1
最佳答案
你能不能这样设置你的数据看看能不能用
this.topUsers = res.body;
在你的模板中
<div class="flex flex w-full" *ngFor="let client of topUsers">
<p class="w-64">{{ client.last_name }} {{ client.first_name }}</p>
</div>
如果不是这种情况,请检查您是否在 app.module.ts 中导入 CommonModule
关于html - NgFor 没有显示我给他的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57521863/