相关疑难解决方法(0)

Angular 获取选定的数据列表对象

这种select单向绑定有效

<select [(ngModel)]="selectedLocation">
    <option *ngFor="let location of allLocationNames" [ngValue]="location">{{location.name}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)

selectedLocation将始终包含选定的位置对象

这种datalist单向绑定似乎不起作用

<h4>Guest: <input type="text" name="guest" [(ngModel)]="selectedGuest" list="options">
  <datalist id=options *ngIf="allGuests">
    <option *ngFor="let guest of allGuests" [ngValue]="guest">{{guest.companyName}}</option>
  </datalist>
</h4>
Run Code Online (Sandbox Code Playgroud)

selectedGuest 将不包含对象,而是包含所选元素的字符串值 (guest.companyName)。

如何在 datalist 示例中获取所选对象?

angular

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1