angular - 如何在 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,
},
},
这是我在这里的第一篇文章,所以我也会感谢任何关于发布问题的建议。先感谢您。
解决方案
我最终在 expressionOptions 中使用正则表达式而不是函数并且它起作用了。问题解决了。
推荐阅读
- python - 从 polygon_perimeter 裁剪图像
- python - 用命令断言
- python - 我如何将“random.choice”与不同的线路同步?
- visual-studio-code - 将 ${localEnv:TOKEN} 加载到 devcontainer.json 时出现问题
- python - Pyinstaller:有没有办法在 MacOS 上为 Windows 和 Linux 打包应用程序(反之亦然)?
- node.js - 如何使用 sqlite3 在 node.js 中更新,如 mongo 上的函数 findByIdAndUpdate?
- git - 什么样的 Git 命令序列可能会导致这个提交图
- python - 训练有效,但预测产生恒定值(使用 pytorch 的 cnn)
- typescript - 在 Firestore 中获取所有可以访问其子项的文档
- javascript - 在按钮单击中显示组件(使用挂钩)