4 回答

TA贡献1936条经验 获得超6个赞
您已经在迭代 booksArr。只需要使用插值来显示数据。尝试这样
<table border="1" *ngIf="bName">
<thead>
<tr>
<th>book ID</th>
<th>book Name</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let b of booksArr">
<td>{{b.bookId}}</td>
<td>{{b.bookName}}</td>
</tr>
</tbody>
</table>

TA贡献1809条经验 获得超8个赞
您已经在使用 迭代书籍数组*ngFor="let b of booksArr"。
您现在想要对数组中每本书的值进行插值。当您位于数组内部时,您可以访问在 中声明的循环变量*ngFor。在这种情况下,循环变量是b。b您现在可以绑定到使用大括号插值的属性。{{b.bookId}}。
<table border="1" *ngIf="bName">
<thead>
<tr>
<th>book ID</th>
<th>book Name</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let b of booksArr">
<td>{{b.bookId}}</td>
<td>{{b.bookName}}</td>
</tr>
</tbody>
</table>

TA贡献1725条经验 获得超7个赞
在这种情况下不需要*ngIf。只需尝试以下操作
<tbody>
<tr *ngFor="let b of booksArr">
<td>{{b.bookId}}</td>
<td>{{b.bookName}}</td>
</tr>
</tbody>
在你的 .ts 文件中你应该改变
constructor(bookId, bookName, cost, quantity)
或者
this.bookName=bookType;
在你的构造函数中
- 4 回答
- 0 关注
- 148 浏览
添加回答
举报