zoukankan      html  css  js  c++  java
  • [ngx-formly] Dynamically hide Form Controls with Angular Formly

    In this lesson we're going to learn how to dynamically hide a form control with Formly's hideExpressions. These expressions are evaluated automatically at runtime whenever a change on our form happens. As a result we can easily hide - say - the city dropdown field when no nation value has been selected yet.

        {
          key: 'cityId',
          type: 'select',
          templateOptions: {
            label: 'Cities',
            options: [],
          },
          expressionProperties: {
            'templateOptions.disabled': model => !model.nationId,
            'model.cityId': '!model.nationId ? null: model.cityId',
          },
          hideExpression: model => {
            return !model.nationId;
          },
          hooks: {
            onInit: (field: FormlyFieldConfig) => {
              field.templateOptions.options = field.form.get('nationId').valueChanges.pipe(
                startWith(this.model.nationId),
                switchMap(nationId => this.dataService.getCities(nationId)),
              );
            },
          },
        },
  • 相关阅读:
    第三次冲刺
    [操作系统]实验四
    第二个冲刺5.0
    第二个冲刺
    学术诚信与职业道德--个人感想
    软件工程——sprint 1回顾总结
    [读书笔记]
    sprint5.0
    [操作系统]3.0
    学习进度条
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12172130.html
Copyright © 2011-2022 走看看