我使用链接到 Angular 8 输入的材料自动完成表单
我是 Angular 的新手,我还在学习。我已经尝试了一些我在 stackoverflow 上找到的解决方案但没有成功(例如:材料自动完成不显示点击列表)
这是我的 HTML 页面:
<mat-form-field>
<input
matInput
type="text"
placeholder="Equipment"
aria-label="Number"
[formControl]="machineControl"
[formControl]="machineFilter"
[matAutocomplete]="auto"
#machineinput
/>
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{ option }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
这是我的打字稿页面:
export class DocumentsListComponent implements OnInit {
machineControl = new FormControl();
options: string[] = [];
filteredOptions: Observable<string[]>;
@ViewChild('machineControl', { static: true }) input: ElementRef;
constructor(public restApi: DocumentsService) {}
ngOnInit() {
this.restApi.getList().then(res => {
[...]
for (const docs of this.Document) …Run Code Online (Sandbox Code Playgroud)