我已经创建了选择,选项是从 API 加载的,问题是当我有一些之前设置的值时,现在我想在这个选择中显示这个我没有看到这个值,点击选择后可以看到标记的选项。这是为什么?我的代码。
<form [formGroup]="form">
<ion-item class="transparent">
<ion-select cancelText="Cancel" formControlName="type">
<ion-select-option *ngFor="let type of types" [value]="type">{{type.name}}</ion-select-option>
</ion-select>
</ion-item>
</form>
ngOnInit() {
this.form = this.fb.group({
type: new FormControl('')
})
this.service.getTypes().then((types) => {
this.types= types;
this.form.controls['type'].setValue(this.types[0]);
});
}
export class Type{
public id: number;
public name: string;
}
请告知,是否可以显示此数据。