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

相关内容

热门资讯

第6分钟辅助!微乐小程序免费黑... 第6分钟辅助!微乐小程序免费黑科技,微乐自建房辅助免费入口(开挂)一直有挂(2026)1、第6分钟辅...
据目击者称!微乐小程序黑科技,... 您好,微信小程序辅助多少钱这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很...
十分钟插件!微乐小程序黑科技,... 十分钟插件!微乐小程序黑科技,微乐家乡小程序脚本(开挂)切实真的是有挂(2026)1、不需要AI权限...
此事备受玩家关注!微乐小程序免... 此事备受玩家关注!微乐小程序免费黑科技,微信微乐辅助(透视)一直是有挂(哔哩哔哩)1、不需要AI权限...
一分钟工具!微乐小程序免费黑科... 您好,微乐小程序免费黑科技这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很...
透视有挂!微乐小程序黑科技,微... 透视有挂!微乐小程序黑科技,微乐多乐跑作弊(透视)都是有挂(哔哩哔哩)1.微乐小程序黑科技 选牌创建...
9分钟教程!微乐小程序免费黑科... 9分钟教程!微乐小程序免费黑科技,微乐小程序自建房插件怎么安装(开挂)都是是有挂(2026)1、实时...
相较于以往!微乐小程序黑科技,... 相较于以往!微乐小程序黑科技,微乐麻将脚本透视(透视)真是是真的挂(哔哩哔哩)1、首先打开微乐麻将脚...
第一分钟教程!微乐小程序免费黑... 第一分钟教程!微乐小程序免费黑科技,微乐南昌辅助神器(开挂)一贯存在有挂(2026)1、首先打开微乐...
刚刚!微乐小程序免费黑科技,微... 刚刚!微乐小程序免费黑科技,微乐小程序挂哪里(透视)总是存在有挂(哔哩哔哩)小薇(辅助器软件下载)致...