angular - 重置后角度表单保持禁用
问题描述
我有一个下拉设置为禁用。但是,每次我重置表单时customerForm.reset()
,下拉菜单都会启用,而不是禁用。
其硬编码为 disabled below = true 。
每次重置后如何将其保持为禁用状态?
<form [formGroup]="customerForm">
<mat-form-field>
<mat-label>Product List</mat-label>
<mat-select
formControlName="product"
[disabled]="true">
<mat-option>Select</mat-option>
<mat-option
*ngFor="let productItem of productList"
[value]="productItem "
>
{{ productItem }}
</mat-option>
</mat-select>
</mat-form-field>
注意:希望保留表单中的值,尽可能不使用 getRawValue。
解决方案
在您的clear/reset
函数中,您可以添加以下内容:
this.customerForm.controls['product'].disabled();
或者
你可以在你的初始化formGroup
customerForm = this.fb.group({
product: [{value: '', disabled: true}]
});
并省略[disabled]="true"
你的mat-select
推荐阅读
- javascript - 在反应钩子中,我如何将新创建的对象传递给状态对象?
- php - 将整个 Excel 行复制到表单域中
- html - 文本变换和翻译的翻转坐标系的行为
- visual-studio-code - VSCode 上的 PHP 语言服务器错误:与服务器的连接已关闭。服务器将重新启动。语言服务器以退出代码 255 退出
- apache-kafka - Kafka偏移重置而不重新启动消费者
- typescript - TypeScript:使用属性装饰器时得到错误的对象
- android - 我的 webview 在默认浏览器中打开网页
- python - torch.nn.conv* 中的 groups 参数如何影响卷积过程?
- javascript - 为什么我不能分配给动态创建的 html 文档的正文?
- javascript - 如何正确地将 Promises 串在一起以进行同步代码执行