首页 > 其他 > 详细

[ngx-formly] Dynamically hide Form Controls with Angular Formly

时间:2020-01-09 19:05:21      阅读:74      评论:0      收藏:0      [点我收藏+]

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)),
          );
        },
      },
    },

 

[ngx-formly] Dynamically hide Form Controls with Angular Formly

原文:https://www.cnblogs.com/Answer1215/p/12172130.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!