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、进入游戏-大厅左侧-新手福利-激活码辅...
透视美元局!aapoker破解... 透视美元局!aapoker破解侠是真的吗(透视)插件(一贯真的有挂);一、aapoker破解侠是真的...
透视规律!德扑圈透视(透视)透... 透视规律!德扑圈透视(透视)透视(好像是有挂)1、完成德扑圈透视透视辅助安装,帮助玩家取得所有比赛的...
透视攻略!aapoker ai... 透视攻略!aapoker ai插件(透视)插件(好像有挂)1、操作简单,无需注册,只需要使用手机进行...
透视脚本!德扑圈有透视吗(透视... 透视脚本!德扑圈有透视吗(透视)透视辅助软件(一直是有挂)1、上手简单,内置详细流程视频教学,新手小...
透视免费!aapoker脚本(... 透视免费!aapoker脚本(透视)免费透视脚本(都是存在有挂);1、下载好aapoker脚本辅助软...
透视辅助!德普之星透视辅助软件... 透视辅助!德普之星透视辅助软件是真的吗(透视)透视辅助软件(切实真的是有挂);运德普之星透视辅助软件...
透视规律!aapoker安装包... 透视规律!aapoker安装包怎么使用(透视)透视软件(一贯有挂)1、aapoker安装包怎么使用a...
透视透视!德普之星的辅助工具介... 透视透视!德普之星的辅助工具介绍(透视)私人局辅助免费(一直有挂);1、让任何用户在无需德普之星的辅...
透视透视!aapoker万能辅... 透视透视!aapoker万能辅助器(透视)脚本(好像真的是有挂)1、让任何用户在无需aapoker万...