angular - 如何从打字稿中使角度输入控件只读?
问题描述
我在 HTML 中有以下内容
<mat-form-field [appearance]="matFormFieldAppearance" style="margin-left:10px;width:50%">
<mat-label>Type</mat-label>
<mat-select formControlName="TypeId" required>
<mat-option *ngFor="let item of TypeList" [value]="item.Id">
{{item.Title}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field [appearance]="matFormFieldAppearance" style="margin-left:10px;width:50%">
<mat-label>Category</mat-label>
<mat-select formControlName="CategoryeId" required>
<mat-option *ngFor="let item of CategoryList" [value]="item.Category">
{{item.Category}}
</mat-option>
</mat-select>
</mat-form-field>
在 TypeScript 中,MatDialog 接收数据,如果 Field1 不为空,我希望将表单字段放入 ReadOnly
this.K = this.matdialogData;
if (this.K.Field1 !== null)
{
this.myForm.controls.CategoryeId.ReadOnly(); //Something like this
this.myForm.controls.TypeId.ReadOnly();//Something like this
}
解决方案
您可以禁用这些字段以使其成为只读。
this.myForm.controls.CategoryeId.disable();
this.myForm.controls.TypeId.disable();
此外,您可以使用样式 pointer-events-none 将类添加到 mat-form-field 以使字段只读。
推荐阅读
- flutter - Dart - 如何将函数作为参数传递
- sql - 如果存在更新,则查询从表中获取更新的记录,否则获取新记录
- php - 如何在 mysql 中建立数据库关系并使用 eloquent 和 join
- java - Maven 强制依赖项使用 Spring Boot 低版本
- javascript - 为什么我的文本输入字段被锁定以进行编辑?
- android - 迁移到 Androidx 后出错。“android.support.constraint.R.styleable.ImageFilterView”转换为“android.constraintlayout.R”
- postgresql - 当子选择很快时,了解为什么“从不存在中删除”会变慢
- firebase - 如何从颤动的firestore文档字段中获取数据?
- jazzy - 编辑 Jazzy HTML 生成以添加自定义链接
- ios - 在 ios swift 中的 NotificationService 中播放流式 URL