![](/img/trans.png)
[英]How to bind mat-autocomplete on change of other mat-autocomplete?
[英]mat-autocomplete not allowing me to select
我刚刚从这里https://v7.material.angular.io/components/autocomplete/examples复制了上面示例中的确切代码
问题是当我 select 在列表中单击它时,它没有显示在顶部的框中。 我希望它基于它在他们的示例中的工作方式。 当我单击该元素时,它显示单击 animation 但实际上没有选择任何内容。
我在控制台中收到此错误。 mat-form-field 必须包含一个 MatFormFieldControl。
这是我的代码。 我正在使用 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>
我认为您需要从 angular 材料中导入: MatAutocompleteModule 和 MatInputModule 。 此外,您需要导入 ReactiveFormsModule
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.