angular 4 中的 compareWith 指令

compareWith directive in angular 4

Angular 4 introduced compareWith directive to compare options to select.

<select [compareWith]="byUId" [(ngModel)]="selectedUsers">
    <option *ngFor="let user of users" [ngValue]="user.UId">{{user.name}}</option>
</select>

这仅适用于 select 控件?或者是否可以使用其他控件?如果是,那怎么办?

这仅适用于 select 个标签。这是 GitHub 上的原始 拉取请求 https://github.com/angular/angular/pull/13349

对我来说只有当我将 ngModel 更改为 value 时才解决。喜欢:

<select [compareWith]="byUId" [(value)]="selectedUsers">
    <option *ngFor="let user of users" [ngValue]="user.UId">{{user.name}}</option>
</select>