angular - Angular 7 Material 自动完成选项未显示
问题描述
我使用的是angular page中的确切代码,唯一的区别是我使用的是 Angular 7 和 @angular/material 7。
组件.html:
<!-- added to see that value is changing -->
<li *ngFor="let street of filteredStreets | async">{{street }}</li>
<form class="example-form">
<input type="text"
matInput
placeholder="Search for a street"
[formControl]="control"
[matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let street of filteredStreets | async" [value]="street">
{{street}}
</mat-option>
</mat-autocomplete>
</form>
组件.ts:
control = new FormControl();
streets: string[] = ['Champs-Élysées', 'Lombard Street', 'Abbey Road', 'Fifth Avenue'];
filteredStreets: Observable<string[]>;
constructor() {
this.filteredStreets = this.control.valueChanges.pipe(
startWith(''),
map(value => this._filter(value))
);
}
private _filter(value: string): string[] {
const filterValue = this._normalizeValue(value);
return this.streets.filter(street => this._normalizeValue(street).includes(filterValue));
}
private _normalizeValue(value: string): string {
return value.toLowerCase().replace(/\s/g, '');
}
解决方案
推荐阅读
- mysql - MYSQL 选择使用 concat 而不是在语句中
- php - shopify嵌入式应用程序hmac验证失败php
- php - 在 PHP 中验证/绕过 .htaccess .htpasswd
- android - 如何去除默认顶部工具栏和 TabBar 之间的阴影 | 安卓
- firebase - “未捕获的 TypeError:无法读取属性‘push’ of null”,使用 Polymer 3 和 polymerfire3
- sql - 在增加主键时向表中添加行
- asp.net-web-api - 通过 Web Api 使用 AAD 客户端和 Outlook.com 等 Microsoft 客户端访问 MS Graph 数据
- java - javaFX - 显示验证码
- python - 如何从 Javascript 代码中提取 URL?- Python
- python - 使用 Numpy datetime64 对象索引/切片 Pandas DataFrame