Angular-Formly: Hide/Disable Fields from Service

烂漫一生 提交于 2019-12-10 21:42:58

问题


I have a service in which i try to disable an angular-formly field:

formField.templateOptions.disabled = true;

Even though the templateOption object is correct, the field is not disabled:

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

Is this not possible?

Thanks.

Edit: Form Code before disabling in service

{
  "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
  }
},

回答1:


If you want a property to be dynamic, you must use expressionProperties. Technically, you don't have to see it via an expression property, but it needs to be present in expression properties because formly has an optimization that basically says if it's not on there, then it won't watch for changes. This is a performance optimization.

You can see dynamic disabled working in this example: http://angular-formly.com/#/example/intro/codementor



来源:https://stackoverflow.com/questions/32904449/angular-formly-hide-disable-fields-from-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!