问题
我有一个ion-select,在控制器中,当用户做某事时,我用1值填充ion-select,并将该值设置为所选的值。ion-select没有显示该值已被选中,但[(ngModel)]具有正确的值。当我打开ion-select时,它会显示列表中的值并被选中,当再次选择列表中的值时,它将遍历ion-select label。
如何使用一个值填充ion-select,并将填充的值设置为选定的值,以便它在ion-select上显示为选定的项?
截图
ion-select

当点击

<ion-item>
<ion-label position="floating">
<span class="required">* </span>Make
</ion-label>
<ion-select [interfaceOptions]="global.compactAlertOptions" id="make" [(ngModel)]="global.valuation.vehicle.make" name="make" #makeRef="ngModel" required>
<ion-select-option *ngFor="let make of makes">{{make}}</ion-select-option>
</ion-select>
</ion-item>
<ion-label *ngIf="makeRef.touched && makeRef.invalid && makeRef.errors.required" class="error">Make is required</ion-label>
控制器
this.global.valuation.vehicle.make = this.vehicleDetails.VehicleMake;
ion-select选项:this.global.valuation.vehicle.make;
this.makes =
发布于 2020-07-08 07:13:40
这通常发生在ngModel中的值在DOM加载<ion-select-option>选项之前设置时。
您必须显式延迟将值设置为ngModel,直到<ion-select>和选项加载到DOM上为止。
您可以通过在组件文件中添加一个setTimeout并在setTimeout的回调中分配ngModel值来实现这一点。
发布于 2020-02-21 19:31:01
在我看来,这与您在模板上使用的一些自定义css有关。因为对select使用浮动与使用堆栈时完全相同,因为select无论如何都会在离子项上展开。这种浮动对离子输入最有效。
在您的情况下,如果未选中该选项,则select应为空,其上方的标签应为空。但是它在项目上,而且在选择的基线上。当您选择该选项时,它将显示在select左对齐的基线中。就像这样:

如果你把浮子移开,你就会明白我的意思。它应该是这样的:

如果您只提供了影响元素对齐的CSS位,就会更容易理解这个问题。
我的猜测是,你有一些风格,只减少离子项目,而不处理对齐和定位的内在元素。
https://stackoverflow.com/questions/60336683
复制相似问题