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

相关内容

热门资讯

透视指南书!hhpoker辅助... 透视指南书!hhpoker辅助软件下载,德普之星透视辅助软件是真的吗(透视)一直真的是有挂(哔哩哔哩...
透视法子!红龙poker有辅助... 透视法子!红龙poker有辅助吗,wepoker私人局外卦(透视)真是存在有挂(哔哩哔哩)红龙pok...
透视教程书!pokemmo手机... 透视教程书!pokemmo手机辅助软件,hhpoker辅助软件(透视)原来真的有挂(哔哩哔哩)1、全...
透视阶段!德普之星辅助器app... 透视阶段!德普之星辅助器app,德普之星辅助器(透视)竟然有脚本方法(哔哩哔哩)1、进入游戏-大厅左...
透视课程!拱趴大菠萝十三水作必... 透视课程!拱趴大菠萝十三水作必弊,哈糖大菠萝怎么挂(透视)切实是有挂(哔哩哔哩)1、进入到拱趴大菠萝...
透视窍要!hhpoker辅助器... 透视窍要!hhpoker辅助器视频,hhpkoer辅助器(透视)好像存在有脚本攻略(哔哩哔哩)1、h...
透视方针!拱趴大菠萝自动计算机... 透视方针!拱趴大菠萝自动计算机器人,werplan免费挂下载(透视)都是是有挂(哔哩哔哩)拱趴大菠萝...
透视操作!德扑圈透视,德普之星... 透视操作!德扑圈透视,德普之星私人局辅助器(透视)确实真的是有脚本教程(哔哩哔哩)1、让任何用户在无...
透视步骤!wepoker作必弊... 透视步骤!wepoker作必弊辅助,wepoker有透视底牌吗(透视)其实真的有挂(哔哩哔哩)wep...
透视策略!德普辅助器怎么用,德... 透视策略!德普辅助器怎么用,德普辅助软件(透视)切实存在有透视app(哔哩哔哩)1、上手简单,内置详...