angular-material - Angular Material 的垫子自动完成输入未按预期禁用
问题描述
我正在尝试禁用 Angular Material Autocomplete 组件。我本来希望能够disabled
在输入上进行设置,但这无济于事。(我还尝试设置disabled
mat-form-field 和 mat-autocomplete。)设置matAutocompleteDisabled
输入阻止了选项显示,但仍然允许在字段中输入。输入设置readonly
阻止了输入,但它不会改变 UI,所以看起来这会让用户感到困惑。这是一个错误,还是我错过了什么?
这是我到目前为止最接近的,使用readonly
(并且禁用没有按预期工作)
<form class="example-form">
<mat-form-field class="example-full-width">
<input type="text"
disabled readonly
placeholder="Pick one"
aria-label="Number"
matInput
[formControl]="myControl"
[matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of options" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</form>
解决方案
您应该使用 formControl 来设置它,例如:
this.formGroupName.controls['myControl'].disable()
推荐阅读
- c++ - main.cpp:1:10:致命错误:opencv2/highgui.hpp:没有这样的文件或目录
- python - 以 django 形式设置默认数据
- javascript - 打印内容
- c++ - 如何使用 duktape 创建插入的对象?
- php - 即使在所有测试完成之前,如何显示失败的 PHPUnit 测试的名称
- python - 优化覆盖类型问题的Python实现
- haskell - haskell 将字符串转换为 Int
- shiny - rmarkdown flexdashboard images 文件夹会自行删除
- c - getline() 在使用 fork() 时重复读取文件
- jms - 调用 setRollbackOnly 后 JMS 消息传递延迟