我想将文本字段设为只读,以便文本字段不可编辑,
我正在使用 Material-UI。
我已经尝试在组件的 .ts 文件中禁用它
this.firstFormGroup.controls['gauthan_nirmit'].disable();
但它不会将数据发回服务器。该控件应该是只读的,但它必须在提交完成后将数据发送回服务器
最佳答案
只需将 readonly 属性添加到组件的 .html 文件中的输入字段
<mat-form-field>
<input matInput readonly number formControlName="gauthan_nirmit" placeholder="" maxlength="5" autocomplete="off" appBlockCopyPaste>
</mat-form-field>
它将使控件只读但控件数据将在提交表单时发送到数据
关于html - 如何在 Angular 12 中制作 Material-UI 输入文本字段 "read only",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68812717/