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

相关内容

热门资讯

透视必备!wepoker有没有... 透视必备!wepoker有没有辅助,wepoker怎么获得好牌-一贯是有辅助技巧(哔哩哔哩)1)免费...
透视揭幕!we-poker是什... 透视揭幕!we-poker是什么软件,wejoker辅助机器人-都是一直总是有辅助工具(哔哩哔哩)透...
透视总结!wepoker辅助脚... 透视总结!wepoker辅助脚本,wepoker怎么设置盖牌-确实是真的有辅助攻略(哔哩哔哩)1、该...
透视必备!wpk俱乐部辅助器,... 透视必备!wpk俱乐部辅助器,wpk俱乐部怎么作弊-都是一直总是有辅助app(哔哩哔哩);1、完成辅...
透视解谜!wpk德州局怎么透视... 透视解谜!wpk德州局怎么透视,wpk透视辅助靠谱吗-切实有辅助方法(哔哩哔哩)德州局怎么透视破解侠...
透视揭露!wepoker模拟器... 透视揭露!wepoker模拟器哪个,we-poker靠谱吗-竟然存在有辅助神器(哔哩哔哩)在进入软件...
透视辅助!hhpoker有没有... 透视辅助!hhpoker有没有作弊辅助,hhpoker是内部控制吗-总是是有辅助软件(哔哩哔哩)1、...
透视普及!aapoker透视插... 透视普及!aapoker透视插件,aapoker万能辅助器-好像一直总是有辅助神器(哔哩哔哩)一、可...
透视解谜!wpk控制牌是真的吗... 透视解谜!wpk控制牌是真的吗,微扑克微乐辅助-真是有辅助神器(哔哩哔哩)1、打开软件启动之后找到中...
透视解谜!wpk透视辅助方法,... 透视解谜!wpk透视辅助方法,wpk德州局透视-本来是有辅助脚本(哔哩哔哩)1、用户打开应用后不用登...