【问题标题】:set a default value on select dropdown using using angular formly使用角度形式在选择下拉列表中设置默认值
【发布时间】:2021-02-08 07:00:15
【问题描述】:

您好,我们如何使用 Angular Formly 库为选择字段设置默认值

    this.uiFormFactory.createSelect(
          Location,
          this.store.select(StoreUtil.getParameterOptions(ParameterId.Location)),
          PersonDetailsFieldLabel.location,
          {
            required: true,
            select: { searchable: true, virtualScroll: true, defaultValue: 'Home' },
            readonly: false,
          }
        ),

【问题讨论】:

    标签: angular angular-formly ngx-formly


    【解决方案1】:

    你可以使用这样的东西:

      form = new FormGroup({});
      options: FormlyFormOptions = {};
      fields: FormlyFieldConfig[] = [
        {
          key: 'select box',
          type: 'select',
          defaultValue: 'value1',
          templateOptions: {
            label: 'select something',
            options: [
              { label: 'value 1', value: 'value1' },
              { label: 'value 2', value: 'value2' },
              { label: 'value 3', value: 'value3' },
            ],
          },
        },
      ];
    
      submit() {
        console.log('submit form');
      }
    }
    <form [formGroup]="form" (ngSubmit)="submit()">
      <formly-form [fields]="fields" [options]="options" [form]="form"></formly-form>
      <button type="submit" class="btn btn-primary submit-button" [disabled]="!form.valid">Submit</button>
    </form>

    当然,你可以随意设置选项数组

    【讨论】:

      猜你喜欢
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-22
      相关资源
      最近更新 更多