小编Woj*_*cki的帖子

NgFor 显示最后一个元素

我有对象数组

[0: {yplace: 11, xrow: 4}1: {yplace: 12, xrow: 4}2: {yplace: 13, xrow: 4} ]

<div class="row-place" *ngFor="let seat of reservation.seats; let i = index" >
  {{seat.xrow}} <input [(ngModel)]="seat.xrow" name="row" type="number" min="0" class="place form-control signup-row">
  {{seat.yplace}} <input [(ngModel)]="seat.yplace" name="place" type="number" min="0" class="place form-control signup-row">
</div>
Run Code Online (Sandbox Code Playgroud)

在 html 中,我有 3 个输入,所有输入都只绑定数组中的最后一个元素?

但是当我使用{{seat.xrow}}并且{{seat.yplace}}显示正常时,我预期

如何使用输入标签进行双向数据绑定。每个输入都有来自数组而不是最后一个元素的唯一索引?

编辑:我有

  reservation: ReservationAdminDto = {
    seats: [],
    email: '',
    phoneNr: ''
 };
Run Code Online (Sandbox Code Playgroud)

ReservationAdminDto.model.ts有一个形式:

export class ReservationAdminDto {
  email: string;
  phoneNr: string;
  seats: SeatDto[]; …
Run Code Online (Sandbox Code Playgroud)

ngfor angular

4
推荐指数
1
解决办法
2118
查看次数

标签 统计

angular ×1

ngfor ×1