额,最近被一个前端的select绑定问题困扰了。就是关于 nz-option 不会默认选中的问题。同一个界面其他的都可以默认选中,唯独遇到几个不行。后来各种尝试查资料……,具体如下:
<nz-select nzAllowClear nzPlaceHolder="" name="equipmentCondition" #name="ngModel"
[(ngModel)]="equipment.equipmentCondition">
<nz-option *ngFor="let item of conditions" nzLabel="{{item.label}}" nzValue="{{item.value}}">
</nz-option>
</nz-select>
方案一: 绑定的类型不能是number.
方案二:绑定的类型必须是number,那么修改为以下的方式:
<nz-select nzAllowClear nzPlaceHolder="" name="equipmentCondition" #name="ngModel"
[(ngModel)]="equipment.equipmentCondition">
<nz-option *ngFor="let item of conditions" nzLabel="{{item.label}}" [nzValue]="item.value">
</nz-option>
</nz-select>
到此,好了。具体原因 [nzValue]=“number”,才是数字。