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

相关内容

热门资讯

透视攻略!HH平台挂(透视)果... 透视攻略!HH平台挂(透视)果然是有辅助插件(哔哩哔哩)1、很好的工具软件,可以解锁游戏的HH平台挂...
透视教程书!智星菠萝可以辅助吗... 透视教程书!智星菠萝可以辅助吗(透视)好像是真的辅助辅助器(哔哩哔哩)智星菠萝可以辅助吗能透视中分为...
透视积累!we poker辅助... 透视积累!we poker辅助器下载(透视)原来存在有辅助下载(哔哩哔哩)1、超多福利:超高返利,海...
透视手筋!竞技联盟辅助插件(透... 透视手筋!竞技联盟辅助插件(透视)确实是真的辅助辅助器(哔哩哔哩)1、上手简单,内置详细流程视频教学...
透视绝活儿!wepoker挂(... 透视绝活儿!wepoker挂(透视)竟然有辅助神器(哔哩哔哩)所有人都在同一条线上,像星星一样排成一...
透视攻略!德普之星辅助器怎么用... 透视攻略!德普之星辅助器怎么用(透视)本来真的有辅助插件(哔哩哔哩)小薇(辅助器软件下载)致您一封信...
透视教材!红龙poker作必弊... 透视教材!红龙poker作必弊指令(透视)真是真的有辅助软件(哔哩哔哩)1.红龙poker作必弊指令...
透视练习!wepoker轻量版... 透视练习!wepoker轻量版书签(透视)真是是有辅助下载(哔哩哔哩)进入游戏-大厅左侧-新手福利-...
透视大纲!wpk控制牌是真的吗... 透视大纲!wpk控制牌是真的吗(透视)好像是有辅助安装(哔哩哔哩)wpk控制牌是真的吗破解侠是真的助...
透视指南书!德扑圈有透视吗(透... 透视指南书!德扑圈有透视吗(透视)好像是真的辅助软件(哔哩哔哩)1、任何德扑圈有透视吗透视是真的假的...