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

相关内容

热门资讯

盘点一款!hhpoker是真的... 盘点一款!hhpoker是真的吗,wepoker游戏安装教程,微扑克教程(有挂辅助)是一款可以让一直...
实测必看!竞技联盟破解版最新版... 1、实测必看!竞技联盟破解版最新版,pokernow辅助工具,黑科技教程(有挂攻略)2、进入游戏-大...
最新技巧!wepoker辅助真... 1、最新技巧!wepoker辅助真的假的,aapoker插件,可靠技巧(有挂透视);详细教程。2、w...
一分钟快速了解!wepoker... 一分钟快速了解!wepoker有机器人吗,德州透视插件,曝光教程(有挂透明)1、很好的工具软件,可以...
专业讨论!wpk辅助软件,hh... 1、专业讨论!wpk辅助软件,hhpoker有没有辅助,2025新版总结(有挂攻略);详细教程。2、...
实测教程!wpk俱乐部辅助器,... 实测教程!wpk俱乐部辅助器,拱趴大菠萝万能辅助器,插件教程(有挂教程)1、点击下载安装,微扑克wp...
科技通报!wepoker辅助工... 科技通报!wepoker辅助工具,aapoker脚本,曝光教程(有挂攻略);最新版2024是一款经典...
实测发现!wepoker破解游... 实测发现!wepoker破解游戏盒子,hardrock作弊,安装教程(有挂透视);最新版2024是一...
攻略讲解!aapoker透视脚... 攻略讲解!aapoker透视脚本入口,wepoker有没有透视方法,可靠教程(有挂攻略)是一款可以让...
每日必看!拱趴大菠萝开挂方法,... 1、每日必看!拱趴大菠萝开挂方法,wepoker辅助器官方,安装教程(有挂辅助)(UU poker、...