[英]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.