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

相关内容

热门资讯

详情透视!德州局透视脚本下载安... 详情透视!德州局透视脚本下载安装最新版本!真是有辅助技巧(有挂辅助)-哔哩哔哩1、让任何用户在无需德...
曝光透视!佛手在线是不是有挂!... 曝光透视!佛手在线是不是有挂!一贯真的是有辅助攻略(确实有挂)-哔哩哔哩暗藏猫腻,小编详细说明佛手在...
必备透视!poker worl... 必备透视!poker world辅助器!真是一直总是有辅助插件(讲解有挂)-哔哩哔哩1、poker ...
总结透视!pokemmo辅助器... 总结透视!pokemmo辅助器手机版下载!切实是有辅助神器(今日头条)-哔哩哔哩一、pokemmo辅...
解密透视!werplan外卦神... 解密透视!werplan外卦神器!总是真的是有辅助教程(有挂方法)-哔哩哔哩werplan外卦神器破...
普及透视!wepoker透视有... 普及透视!wepoker透视有吗!真是存在有辅助工具(有挂总结)-哔哩哔哩1、许多玩家不知道wepo...
解谜透视!哈糖大菠萝怎么开挂!... 解谜透视!哈糖大菠萝怎么开挂!一贯是有辅助插件(有挂辅助)-哔哩哔哩1、金币登录送、破产送、升级送、...
曝光透视!智星菠萝辅助!一贯一... 曝光透视!智星菠萝辅助!一贯一直都是有辅助方法(确实有挂)-哔哩哔哩暗藏猫腻,小编详细说明智星菠萝辅...
了解透视!newpoker脚本... 了解透视!newpoker脚本!总是一直都是有辅助攻略(有挂方针)-哔哩哔哩1、操作简单,无需new...
详情透视!智星德州辅助译码插件... 详情透视!智星德州辅助译码插件靠谱吗!一贯存在有辅助方法(存在有挂)-哔哩哔哩1、智星德州辅助译码插...