Angularmat-autocomplete未显示下拉选项
创始人
2024-10-28 06:31:04
0
  1. 确保输入框绑定了matAutocomplete指令,并检查matAutocomplete选项的命名是否正确。

  2. 确保提供了正确的数据源。

  3. 检查mat-form-field是否正确包含了mat-autocomplete。

  4. 确保app.module.ts中包含了MatAutocompleteModule。

  5. 检查提供的数据源是否为空或格式不正确。

以下是一个示例代码:

HTML:


  
  
    
      {{ country }}
    
  

TS:

import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Observable } from 'rxjs';
import { startWith, map } from 'rxjs/operators';

@Component({
  selector: 'autocomplete-example',
  templateUrl: 'autocomplete-example.html',
  styleUrls: ['autocomplete-example.css'],
})
export class AutocompleteExample {
  countryCtrl = new FormControl();
  countries: string[] = ['USA', 'Canada', 'Germany', 'Italy', 'France'];
  filteredCountries: Observable;

  constructor() {
    this.filteredCountries = this.countryCtrl.valueChanges.pipe(
      startWith(''),
      map((value) => this.filter(value))
    );
  }

  filter(value: string): string[] {
    const filterValue = value.toLowerCase();

    return this.countries.filter((country) =>
      country.toLowerCase().includes(filterValue)
    );
  }
}

相关内容

热门资讯

重要通知!werplan外挂,... 1、重要通知!werplan外挂,wepoker可以免费玩吗,可靠教程(有挂攻略);详细教程。2、w...
分享一款!wepoker怎么挂... 分享一款!wepoker怎么挂飞机,有没有人wepoker,必备教程(有挂技巧);支持多人共享记分板...
技巧知识分享!菠萝辅助器免费版... 技巧知识分享!菠萝辅助器免费版的功能介绍,wepoker有辅助工具吗,详细教程(有挂技巧)是由北京得...
玩家必备攻略!we-poker... 玩家必备攻略!we-poker辅助软件教程,破解辅助插件wepoker,2025新版教程(有挂技巧)...
热点讨论!wepoker轻量版... 1、热点讨论!wepoker轻量版透视,hhpoker有没有外挂,软件教程(有挂攻略);详细教程。2...
一分钟教会你!hhpoker有... 一分钟教会你!hhpoker有没有辅助,hhpoker德州透视挂,透明挂教程(有挂软件);玩家必备必...
发现玩家!德普软件,佛手大菠萝... 发现玩家!德普软件,佛手大菠萝辅助,wpk教程(有挂软件)是一款可以让一直输的玩家,快速成为一个“必...
新手必备!菠萝辅助器免费版的功... 新手必备!菠萝辅助器免费版的功能介绍,wepoker有辅助器吗,扑克教程(有挂教程);玩家必备必赢加...
一分钟了解!德普之星透视辅助插... 一分钟了解!德普之星透视辅助插件,epoker免费透视脚本,解密教程(有挂攻略);玩家必备必赢加哟《...
热点讨论!德州局hhpoker... 热点讨论!德州局hhpoker,约局吧如何查看是否有挂,教你教程(有挂神器);支持多人共享记分板与复...