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

相关内容

热门资讯

揭秘关于!wepoker免费透... 揭秘关于!wepoker免费透视脚本,wepoker科技辅助器,2025新版总结(有挂技巧)这是由厦...
实测分享!wepoker有辅助... 实测分享!wepoker有辅助吗,wepoker透视脚本网页,力荐教程(有挂神器)是一款可以让一直输...
专业讨论!aapoker如何设... 1、专业讨论!aapoker如何设置胜率,wpk辅助购买,教你攻略(有挂攻略);详细教程。2、aap...
科普!安装不了wepoker,... 科普!安装不了wepoker,wepoker插件程序激活码,技巧教程(有挂神器)准备好在wepoke...
推荐攻略!wepoker有辅助... 推荐攻略!wepoker有辅助工具吗,智星德州有脚本吗,详细教程(有挂技巧)1、很好的工具软件,可以...
推荐攻略!cloudpoker... 这是一款非常优秀的cloudpoker怎么开挂 ia辅助检测软件,能够让你了解到cloudpoker...
玩家必知教程!wepoker辅... 玩家必知教程!wepoker辅助插件功能,hhpoker到底可以作弊码,详细教程(有挂攻略)是由北京...
来一盘!红龙poker辅助工具... 来一盘!红龙poker辅助工具,wepoker有透视吗,玩家教程(有挂教程),支持语音通讯、好友开房...
热点推荐!wepoker轻量版... 1、热点推荐!wepoker轻量版辅助,悦扑克脚本,2025版教程(有挂软件)。2、wepoker轻...
推荐几款新版!wepoker游... 1、推荐几款新版!wepoker游戏的安装教程,德普之星有透视辅助吗,揭秘教程(有挂透明)。2、德普...