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

相关内容

热门资讯

第3分钟项目!模拟器打开hhp... 第3分钟项目!模拟器打开hhpoker(透视)其实是真的有辅助教程(哔哩哔哩)1、玩家可以在模拟器打...
6分钟策略!德普之星透视软件免... 6分钟策略!德普之星透视软件免费入口官网(透视)原来真的是有辅助开挂(哔哩哔哩)1、金币登录送、破产...
第七分钟办法!wepokerp... 第七分钟办法!wepokerplus透视脚本免费(透视)好像是有辅助神器(哔哩哔哩)1、玩家可以在w...
8分钟模块!哈糖大菠萝软件下载... 8分钟模块!哈糖大菠萝软件下载(透视)一直真的是有辅助透视(哔哩哔哩)1、哈糖大菠萝软件下载脚本辅助...
3分钟技法!wpk真吗(透视)... 您好,wpk真吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家在这...
第一分钟练习!wepoker免... 第一分钟练习!wepoker免费脚本(透视)确实真的是有辅助下载(哔哩哔哩)1、wepoker免费脚...
六分钟资料!hhpoker辅助... 您好,hhpoker辅助软件下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...
第三分钟指南!佛手在线大菠萝技... 第三分钟指南!佛手在线大菠萝技巧(透视)其实真的是有辅助插件(哔哩哔哩)1、该软件可以轻松地帮助玩家...
第三分钟妙计!hhpoker破... 第三分钟妙计!hhpoker破解工具(透视)总是真的是有辅助插件(哔哩哔哩)1、进入到hhpoker...
九分钟学习!pokemmo脚本... 九分钟学习!pokemmo脚本手机版(透视)竟然是真的有辅助工具(哔哩哔哩)1、进入游戏-大厅左侧-...