【问题标题】:How to check a select box option in Ionic framework from the controller using Angular 8+?如何使用 Angular 8+ 从控制器检查 Ionic 框架中的选择框选项?
【发布时间】:2021-01-23 23:53:38
【问题描述】:

我有一个 FormGroup 如下:

public form = this.fb.group({
        name: ['', [Validators.minLength(3), Validators.required]],
        category: ['', [Validators.required]],
        start_date: ['', [Validators.required]],
        end_date: ['', [Validators.required]],
        front_image: ['', [Validators.required]],
        description: ['']
    }, {validators: [verifyDates]})

我在 html formGroup 中的选择字段如下:

 <ion-item>
  <ion-label>{{'selectCat' | translate}}</ion-label>
  <ion-select placeholder="{{'selectCatPlaceholder' | translate}}" formControlName="category" required>
    <ion-select-option  *ngFor="let cat of catService.categories" [value]="cat">{{cat.get('name_' + trans.currentLang)}}</ion-select-option>
  </ion-select>
</ion-item>

有没有办法从控制器检查正确的选项?

我正在以这种方式更新 init 上的表单控件

this.form.get('category').setValue(cat[0])

它会正确更新表单值,但不会选中前端的框。我使用表单生成器而不是 ngModels,我以前使用带有 formControl 的 ngModels 但不是它说我们不能再做,我找不到办法。有人可以帮忙吗?

【问题讨论】:

  • "但不勾选前端的复选框"是什么意思?
  • 输入不会像通过设置值那样随着选择而更新。有没有办法将 ngModel 与表单生成器一起使用?
  • 您是否使用&lt;form&gt; 标签并绑定到您的表单? &lt;form [formGroup]="form"&gt;

标签: angular ionic-framework ion-select


【解决方案1】:

试试这个

value ="{{cat}}"

【讨论】:

    猜你喜欢
    • 2016-03-14
    • 1970-01-01
    • 2011-01-24
    • 1970-01-01
    • 2012-04-24
    • 2017-10-27
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    相关资源
    最近更新 更多