有一个标记:
<div class="scroll">
<table class="table table-striped">
<thead>
<tr>
<th>Image</th>
<th>Name</th>
<th>Author</th>
<th>Year</th>
<th>ISBN</th>
<th>Price</th>
<th>Count</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let book of bookService.bookList">
<td><img src="../../{{book.ImagePath}}" width="100" height="150"></td>
<td>{{book.Name}}</td>
<td>{{book.Author}}</td>
<td>{{book.Year}}</td>
<td>{{book.ISBN}}</td>
<td>{{book.Price}}</td>
<td>{{book.Count}}</td>
<td>
<input type="text" name="Count" [(ngModel)]="Count">
<button class="btn btn-block btn-outline-success" (click)="onAdd(book, Count)"><i class="fa fa-plus"></i></button>
</td>
</tr>
</tbody>
最后一列如下所示:

问题如下:当填充一个TextBox时,该列中的所有TextBoxes都被填充。

我该如何解决这个问题?尝试为文本字段提供唯一的名称,并将此单元格推入form,但都不起作用。
发布于 2018-09-10 21:54:12
所有输入都具有相同的[(ngModel)]="Count"和名称,因此如果更新一个输入,则所有输入都将被更新
如果你有一个count的数组,你可以解决这个问题。所以它会是这样的
<tr *ngFor="let book of bookService.bookList; let i = index">
...
<input type="text" [name]="'count' + i" [(ngModel)]="count[i]">https://stackoverflow.com/questions/52259299
复制相似问题