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有没有辅助"详细辅助wepoke教程(代打辅助攻略)准备好在hhpoker有...
透视科技"hhpok... 透视科技"hhpoker可以控制吗"详细辅助必备教程(免费辅助器神器)关于hhpoker可以控制吗机...
透视数据"德普之星透... 透视数据"德普之星透视辅助软件激活码"详细辅助实用技巧(辅助器透视)科技教程也叫必备教程,这是一款功...
透视能赢"德扑圈透视... 透视能赢"德扑圈透视挂"详细辅助2025新版教程(透视脚本免费下载pc透视)1、玩家可以在德扑圈透视...
透视科技"aapok... 透视科技"aapoker辅助器是真的吗"详细辅助wpk教程(可以透视码技巧)准备好在aapoker辅...
辅助透视"poker... 辅助透视"poker辅助器免费安装"详细辅助分享教程(开挂透明);大神普及一款德州ai内幕,确定了p...
透视规律"wepok... 透视规律"wepoker可以开透视吗"详细辅助必胜教程(俱乐部辅助技巧);支持多人共享记分板与复盘,...
透视ai代打"hhp... 透视ai代打"hhpoker外挂靠谱吗"详细辅助专业教程(有辅助工具攻略)是一款可以让一直输的玩家,...
透视了解"wpk私人... 透视了解"wpk私人辅助"详细辅助黑科技教程(透视脚本免费透视);科技安装教程;136704302。...
透视软件"werpl... 透视软件"werplan怎么透视"详细辅助普及教程(免费透视脚本技巧)科技教程也叫必备教程,这是一款...