首页 > 解决方案 > 如何在 Angular 5 中的 Formly 中修改字段模板选项的最大值?

问题描述

我想根据另一个字段值设置 Formly 字段之一的最大值(templateOptions)。我写了一个计算这个值的函数。关于字段在构造函数中初始化如何修改字段的最大值?

我尝试从外部函数 getDiscountSo() 设置值:

this.fields['sosnowiec.discount'].templateOptions.max = val;

但它不影响字段最大值。

{
  className: 'col-4',
  key: 'sosnowiec.discount',
  type: 'input',
  hideExpression: '!model.citySosnowiec' && '!model.sosnowiec.dayCount',
  templateOptions: {
  label: 'Discount',
  type: 'number',
  min: 0,
  max: this.getDiscountSo();
  required: true,
  },
},

这是我在这里的第一篇文章,所以我也会感谢任何关于发布问题的建议。先感谢您。

标签: angulartypescriptangular-formly

解决方案


我最终在 expressionOptions 中使用正则表达式而不是函数并且它起作用了。问题解决了。


推荐阅读