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

相关内容

热门资讯

轻量版八分钟!wepoke有挂... 轻量版八分钟!wepoke有挂网上德州微扑克辅助(其实真的有挂)-知乎1、用户打开应用后不用登录就可...
挂一分钟!来玩德州app服务器... 挂一分钟!来玩德州app服务器在哪里德州aa辅助(果真真的有挂)-今日头条小薇(透视辅助)致您一封信...
插件1分钟!wpk ai是有w... 插件1分钟!wpk ai是有wopoker德州真的有挂(的确真的有挂)-哔哩哔哩1、完成wopoke...
安卓版本6分钟!轰趴大菠萝十三... 安卓版本6分钟!轰趴大菠萝十三水辅助德州ai智能辅助(果然真的有挂)-知乎1、轰趴大菠萝十三水辅助系...
ai辅助五分钟!微扑克的辅助工... 您好,云扑克是否有外挂这款游戏可以开挂的,确实是有挂的,需要了解加微【487309276】很多玩家在...
新版八分钟!aapoker辅助... 新版八分钟!aapoker辅助工具wpk俱乐部有外挂(好像真的有挂)-小红书1、下载好wpk俱乐部有...
安卓版九分钟!德州之星辅助we... 安卓版九分钟!德州之星辅助wepoke ai辅助(果然真的有挂)-微博客户端;1)德州之星辅助辅助挂...
渠道八分钟!pokernow可... 渠道八分钟!pokernow可以加注德州ai辅助神器(其实真的有挂)-小红书;1、让任何用户在无需p...
最新款7分钟!gg扑克辅助we... 最新款7分钟!gg扑克辅助wepoke模拟器(果然真的有挂)-百度知乎;1、打开软件启动之后找到中间...
安装1分钟!nzt德州辅助软件... 安装1分钟!nzt德州辅助软件微扑克辅助软件(都是真的有挂)-百度知乎;1、点击下载安装,微扑克辅助...