Angular-Formly:隐藏/禁用服务字段

2024-04-22

我有一项服务,其中我尝试禁用角度形式字段:

formField.templateOptions.disabled = true;

即使 templateOption 对象是正确的,该字段也不会被禁用:

"templateOptions": {
    "type": "text",
    "placeholder": "",
    "label": "Single Line Test",
    "disabled": true
  },

这不可能吗?

Thanks.

编辑:在服务中禁用之前形成代码

{
  "type": "input",
  "key": "single_line_test",
  "templateOptions": {
    "type": "text",
    "placeholder": "",
    "label": "Single Line Test"
  },
  "data": {},
  "validation": {
    "messages": {},
    "errorExistsAndShouldBeVisible": false
  },
  "id": "formly_2_input_single_line_test_3",
  "name": "formly_2_input_single_line_test_3",
  "formControl": {
    "$validators": {},
    "$asyncValidators": {},
    "$parsers": [],
    "$formatters": [
      null
    ],
    "$viewChangeListeners": [],
    "$untouched": true,
    "$touched": false,
    "$pristine": true,
    "$dirty": false,
    "$valid": true,
    "$invalid": false,
    "$error": {},
    "$name": "formly_2_input_single_line_test_3",
    "$options": null
  }
},

如果您希望属性是动态的,则必须使用expressionProperties。从技术上讲,您不必通过表达式属性查看它,但它需要出现在表达式属性中,因为 formly 有一个优化,基本上表示如果它不存在,那么它不会监视更改。这是一个性能优化。

您可以在此示例中看到动态禁用的工作原理:http://angular-formly.com/#/example/intro/codementor http://angular-formly.com/#/example/intro/codementor

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angular-Formly:隐藏/禁用服务字段 的相关文章

随机推荐