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、这是跨平台的德普之...
透视辅助!wepoker辅助器... 透视辅助!wepoker辅助器是真的吗,we-poker有人玩吗,手段教程(果然真的有挂)-哔哩哔哩...
透视稳定!hhpoker免费透... 透视稳定!hhpoker免费透视脚本(透视)开挂辅助器(总是是真的挂)-哔哩哔哩1、玩家可以在hhp...
透视规律!如何下载wepoke... 透视规律!如何下载wepoker安装包,wepoker有没有插件,窍要教程(总是真的有挂)-哔哩哔哩...
透视机器人!wpk辅助购买(透... 您好,wpk辅助购买这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家...
透视好友!hhpoker必备开... 透视好友!hhpoker必备开挂,wepoker免费脚本咨询,演示教程(真是有挂)-哔哩哔哩1、在w...
透视中牌率!wpk软件是真的吗... 透视中牌率!wpk软件是真的吗(透视)开挂辅助方法(一直真的有挂)-哔哩哔哩1、wpk软件是真的吗a...
透视系统!wepoker私人局... 透视系统!wepoker私人局辅助,pokemmo辅助工具,指引教程(总是真的有挂)-哔哩哔哩1、实...
透视ios!拱趴大菠萝辅助方法... 透视ios!拱趴大菠萝辅助方法(透视)开挂辅助挂(真是存在有挂)-哔哩哔哩拱趴大菠萝辅助方法辅助器中...
透视攻略!wepoker有没有... 透视攻略!wepoker有没有机器人,hhpoker脚本下载,法子教程(一贯真的有挂)-哔哩哔哩1、...