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)
    );
  }
}

相关内容

热门资讯

透视规律!pokemmo辅助脚... 透视规律!pokemmo辅助脚本(透视)竟然真的有辅助神器(有挂分享)-哔哩哔哩1、起透看视 pok...
透视好友房!wpk免费辅助(透... 透视好友房!wpk免费辅助(透视)确实真的是有辅助平台(新版有挂)-哔哩哔哩wpk免费辅助脚本下载中...
透视辅助!哈糖大菠萝有没有挂(... 透视辅助!哈糖大菠萝有没有挂(透视)一贯是真的辅助插件(的确有挂)-哔哩哔哩1、全新机制【哈糖大菠萝...
透视智能ai!pokemmo内... 透视智能ai!pokemmo内置修改器(透视)确实有辅助下载(有挂技巧)-哔哩哔哩1、许多玩家不知道...
透视实锤!wejoker辅助脚... 透视实锤!wejoker辅助脚本(透视)都是存在有辅助软件(有挂分析)-哔哩哔哩1、玩家可以在wej...
透视讲解!wepoker辅助器... 透视讲解!wepoker辅助器下载(透视)果然有辅助app(有挂功能)-哔哩哔哩wepoker辅助器...
最终!德普之星有透视辅助吗(透... 最终!德普之星有透视辅助吗(透视)切实有辅助神器(确实有挂)-哔哩哔哩1、最终!德普之星有透视辅助吗...
相较于以往!we poker游... 相较于以往!we poker游戏下(透视)一直真的是有辅助修改器(有挂辅助)-哔哩哔哩1、起透看视 ...
迎来新发展!wepoker安装... 迎来新发展!wepoker安装教程(透视)一贯是真的辅助安装(有挂方法)-哔哩哔哩wepoker安装...
透视挂!德州局透视脚本免费版下... 透视挂!德州局透视脚本免费版下载手机版(透视)好像存在有辅助修改器(有挂方法)-哔哩哔哩1、德州局透...