简体   繁体   English

垫子自动完成不允许我 select

[英]mat-autocomplete not allowing me to select

在此处输入图像描述 I just copied the exact code from the top example from herehttps://v7.material.angular.io/components/autocomplete/examples我刚刚从这里https://v7.material.angular.io/components/autocomplete/examples复制了上面示例中的确切代码

The problem is when I select something by clicking on it in the list, it isn't showing up in the box at the top.问题是当我 select 在列表中单击它时,它没有显示在顶部的框中。 I would expect it to based on how it worked in their example.我希望它基于它在他们的示例中的工作方式。 When I click the element, it shows the click animation but nothing is actually selected.当我单击该元素时,它显示单击 animation 但实际上没有选择任何内容。

I am getting this error in the console.我在控制台中收到此错误。 mat-form-field must contain a MatFormFieldControl. mat-form-field 必须包含一个 MatFormFieldControl。

Here is my code.这是我的代码。 I am using angular v13我正在使用 angular v13

 import { Component, OnInit } from '@angular/core'; import {FormControl} from "@angular/forms"; @Component({ selector: 'app-autocomplete-display-example', templateUrl: './autocomplete-display-example.component.html', styleUrls: ['./autocomplete-display-example.component.css'] }) export class AutocompleteDisplayExampleComponent{ myControl = new FormControl(); options: string[] = ['One', 'Two', 'Three']; }
 <form class="example-form"> <mat-form-field class="example-full-width"> <input type="text" 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>

I think you need to import: MatAutocompleteModule and MatInputModule from angular material.我认为您需要从 angular 材料中导入: MatAutocompleteModule 和 MatInputModule 。 Moreover you need to import ReactiveFormsModule此外,您需要导入 ReactiveFormsModule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在其他mat-autocomplete更改时绑定mat-autocomplete? - How to bind mat-autocomplete on change of other mat-autocomplete? mat-autocomplete 选项无法找到属性 - mat-autocomplete options not able to find property 垫子自动完成中的无限滚动 angular 11 - Infinite scroll in mat-autocomplete angular 11 Mat-autocomplete 在 ngOnInit() 中不起作用,Map() 不起作用 - Mat-autocomplete is not working in ngOnInit(), Map() is not working 如何在 formBuilder 上禁用 mat-autocomplete? - How to disable mat-autocomplete on formBuilder? 按下Tab键时如何选择垫子选项?它应该像垫子自动完成角度6中的输入按钮一样工作 - How can we select mat option when press on tab key?, it should work like enter button in mat-autocomplete angular 6 如何显示名称但从 mat-autocomplete select 的对象中获取某些其他属性的值? 角-角材料 - How to display a name but take the values of some other property from the object from mat-autocomplete select? Angular- Angular Material mat-autocomplete:选择后需要重置选项列表 - mat-autocomplete: Need to Reset the List of Options After a Selection is Made Angular5 - 如何检测垫子自动完成中的空字段或已删除字段? - Angular5 - How to detect empty or deleted field in mat-autocomplete? Angular 9 mat-autocomplete 不能与 switchmap 运算符一起正常工作 - Angular 9 mat-autocomplete not working properly with switchmap operator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM