问题描述
我有一项服务,其中我尝试禁用角度形式字段:
I have a service in which i try to disable an angular-formly field:
formField.templateOptions.disabled = true;
即使templateOption对象正确,该字段也不会被禁用:
Even though the templateOption object is correct, the field is not disabled:
"templateOptions": {
"type": "text",
"placeholder": "",
"label": "Single Line Test",
"disabled": true
},
这不可能吗?
谢谢。
编辑:禁用服务前的表格代码
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
}
},
推荐答案
如果您希望属性是动态的,则必须使用 expressionProperties
。从技术上讲,您不必通过表达式属性来查看它,但它需要存在于表达式属性中,因为形式上有一个优化,基本上说如果它不在那里,那么它将不会监视更改。这是性能优化。
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
这篇关于Angular-Formly:隐藏/禁用服务中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!