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

相关内容

热门资讯

现有关情况通报如下!hhpok... 现有关情况通报如下!hhpoker怎么开透视(透视)天天互娱辅助器免费下载(本来是有辅助修改器)-哔...
透视规律!poker红龙辅助(... 透视规律!poker红龙辅助(透视)大菠萝怎么提高好牌几率(切实有辅助神器)-哔哩哔哩1、大菠萝怎么...
值得注意的是!epoker透视... 值得注意的是!epoker透视(透视)凑一桌游戏作必弊(竟然真的有辅助下载)-哔哩哔哩该软件可以轻松...
连日来!哈糖大菠萝破解器(透视... 连日来!哈糖大菠萝破解器(透视)微信小程序哥哥打大a辅助(真是有辅助神器)-哔哩哔哩1、每一步都需要...
透视存在!pokemmo手机版... 透视存在!pokemmo手机版脚本免费(透视)西部透视辅助(好像存在有辅助app)-哔哩哔哩1、玩家...
透视新版!拱趴大菠萝怎么开挂(... 透视新版!拱趴大菠萝怎么开挂(透视)三哥玩辅助器软件(好像存在有辅助软件)-哔哩哔哩1、三哥玩辅助器...
据目击者称!wepoker怎么... 据目击者称!wepoker怎么设置透视(透视)创思维激k辅助插件(一贯有辅助插件)-哔哩哔哩一、创思...
透视游戏!wepoker正确养... 透视游戏!wepoker正确养号方法(透视)甘肃白银麻将辅助软件(切实是真的辅助修改器)-哔哩哔哩;...
事发当天!wejoker辅助软... 事发当天!wejoker辅助软件视频(透视)皇豪互众智能辅助器(原来真的是有辅助平台)-哔哩哔哩1、...
经核实!wepoker看底牌(... 经核实!wepoker看底牌(透视)新天道怎么看底牌(果然真的是有辅助插件)-哔哩哔哩1、新天道怎么...