我有一个包含许多输入的页面,我想将其设为“ readOnly
”我找到了这个解决方案: How to change HTML element readonly and required attribute in Angular2 Typescript?
但我不想单独为每个输入做这件事。
如何将 readOnly
属性添加到某些 div 中的所有输入。
原文由 John Doe 发布,翻译遵循 CC BY-SA 4.0 许可协议
我有一个包含许多输入的页面,我想将其设为“ readOnly
”我找到了这个解决方案: How to change HTML element readonly and required attribute in Angular2 Typescript?
但我不想单独为每个输入做这件事。
如何将 readOnly
属性添加到某些 div 中的所有输入。
原文由 John Doe 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果您的意思是一次禁用 Angular 表单中的所有输入:
1-反应形式:
myFormGroup.disable() // where myFormGroup is a FormGroup
2-模板驱动形式(NgForm):
您应该在 NgForm 变量中获取 NgForm(例如,名为 myNgForm)然后
myNgForm.form.disable() // where form here is an attribute of NgForm
// & of type FormGroup so it accepts the disable() function
如果是 NgForm ,请注意在正确的时间调用 disable 方法
要确定何时调用它,您可以 在此 Stackoverflow 答案 中找到更多详细信息
原文由 Ahmed Elkoussy 发布,翻译遵循 CC BY-SA 4.0 许可协议
2 回答3.3k 阅读
1 回答974 阅读✓ 已解决
1 回答1.2k 阅读
在输入字段中试试这个:
希望,这会奏效。