ion-select with form builder 不显示正确的值
ion-select with form builder doesn't show correct value
.html
<ion-select formControlName="type">
<ion-select-option value="t?.id" *ngFor="let t of (issueTypes$ | async)?.result;"> {{t?.name}}
</ion-select-option>
</ion-select>
.ts
init() {
this.form = this.formBuilder.group({
type: ['', Validators.required],
});
}
save() {
const maintenance: Maintenance = {
type: this.form.value.type,
};
}
调试
为什么 type
显示 t?.id
作为值?
您需要绑定值。像这样
<ion-select-option [value]="t?.id" *ngFor="let t of (issueTypes$ | async)?.result;"> {{t?.name}}
另外:我认为您需要将表单数据获取为:
this.<FORM>.get('<FIELD>').value
需要正确设置其他几个项目才能使其正常工作。如果您需要更多帮助,请 post 完整的表格代码
.html
<ion-select formControlName="type">
<ion-select-option value="t?.id" *ngFor="let t of (issueTypes$ | async)?.result;"> {{t?.name}}
</ion-select-option>
</ion-select>
.ts
init() {
this.form = this.formBuilder.group({
type: ['', Validators.required],
});
}
save() {
const maintenance: Maintenance = {
type: this.form.value.type,
};
}
调试
为什么 type
显示 t?.id
作为值?
您需要绑定值。像这样
<ion-select-option [value]="t?.id" *ngFor="let t of (issueTypes$ | async)?.result;"> {{t?.name}}
另外:我认为您需要将表单数据获取为:
this.<FORM>.get('<FIELD>').value
需要正确设置其他几个项目才能使其正常工作。如果您需要更多帮助,请 post 完整的表格代码