angular - 角材料垫-自动完成打开面板
问题描述
我有带有自动完成字段的模态。我将 Angular 5 与 Angular 材料 2 一起使用。当模态加载时,第一个字段的面板始终处于打开状态...
如何避免这种情况?
我试图在另一个字段上使用 autofocus 属性,但它不起作用......
<form name="indexation">
<br>
<div class="row">
<div class="col-md-12">
<mat-form-field class="index-full-width">
<input
matInput
type="text"
[(ngModel)]="patientChoice"
placeholder="Patient"
aria-label="Patient"
[matAutocomplete]="autoPatient"
[formControl]="myControl">
<mat-autocomplete (optionSelected)="selectPat()" #autoPatient="matAutocomplete" [displayWith]="displayFnPat">
<mat-option *ngFor="let patient of filteredPatients | async" [value]="patient">
<span>{{ patient.lastName }}</span>
<small>{{patient.firstName}}</small> |
<span>né(e) le {{ patient.dateNaissance }}</span> |
<small>IPP: {{patient.ipp}}</small>
</mat-option>
</mat-autocomplete>
</mat-form-field>
</div>
</div>
<br>
这个问题是否来自材料?
解决方案
当有要显示的选项并且该字段具有焦点时,结果面板将自动打开。默认情况下,对话框会将焦点设置在第一个可聚焦元素上,因此我认为这就是为什么在对话框加载时自动完成功能会打开的原因。为避免这种情况,请autoFocus: false
在启动对话框时使用 MatDialogConfig 选项。
推荐阅读
- c - 高级 C 问题:请解释 C 构造 *({ foo(&bar); &bar; })
- c - 如何在 C 中将文本文件作为命令行参数
- javascript - 在 javascript 对象中搜索任何值
- kubernetes - 如何为 kubernetes 入口基本身份验证设置辅助密钥
- python - Python,如何快速获取步幅(例如 500)的帧?
- r - R中的子集公式对象
- postgresql - 在 PostgreSQL 中找不到函数
- javascript - forEach() 的意外输出
- math - 如何对三个约束变量 (x+y+z=1) 进行 ARIMA 时间序列预测?
- javascript - 需要在节点中的类