如何禁用文本区域或mat-form-field [英] How to disable a text area or mat-form-field
问题描述
我正在为表单字段"使用Angular(4)+ Angular材质和反应性表单.我该如何禁用呢?我试图用Google搜索诸如 disabled ="true" 之类的东西.您能告诉我正确的语法吗?那一定很容易.谢谢!
I am using Angular (4) + Angular Material and Reactive Forms for my Form Field. How can I disable that? I tried to google for things like disabled="true" or something like that. May can you show me the right syntax? That must be easy. Thanks!
我的例子:
<mat-form-field class="xxx-form-full-with">
<textarea matInput placeholder="My description" formControlName="xxx"></textarea>
</mat-form-field>
推荐答案
具有反应形式 [disabled]
无效.您需要改为在formControl上设置禁用状态:
With reactive forms [disabled]
will not work.
You need to set the disabled status on the formControl instead:
this.myForm = this.formBuilder.group({
xxx: [{value: 'someValue', disabled:true}]
})
还请记住,在执行此操作时,例如在提交时,此字段不会包含在表单对象中.如果要检查所有值(包括禁用值),请使用:
Also remember when doing this, this field will not be included in the form object e.g when submitting. If you want to inspect all values, disabled included, use:
this.myForm.getRawValue();
这篇关于如何禁用文本区域或mat-form-field的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!