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)哈糖大菠萝助手辅助插件:进一步...
解谜透视!约局吧德州有挂吗!一... 解谜透视!约局吧德州有挂吗!一贯存在有辅助软件(详细教程)-哔哩哔哩1)约局吧德州有挂吗辅助插件:进...
解迷透视!hhpoker辅助挂... 解迷透视!hhpoker辅助挂是真的吗,智星德州可以透视吗,方案教程(有挂方法)-哔哩哔哩1、完成h...
详情透视!hh poker辅助... 详情透视!hh poker辅助器先试用,红龙poker辅助器免费观看,绝活教程(有挂攻略)-哔哩哔哩...
详情透视!大菠萝免费辅助!好像... 详情透视!大菠萝免费辅助!好像是真的有辅助app(真的有挂)-哔哩哔哩1、大菠萝免费辅助公共底牌简单...
解谜透视!哈糖大菠萝有没有挂!... 解谜透视!哈糖大菠萝有没有挂!原来存在有辅助技巧(有挂助手)-哔哩哔哩哈糖大菠萝有没有挂是不是有人用...
辅助透视!pokemmo免费脚... 辅助透视!pokemmo免费脚本,安装不了wepoker,方案教程(有挂总结)-哔哩哔哩安装不了we...
有挂透视!聚星ai辅助工具下载... 有挂透视!聚星ai辅助工具下载!竟然真的是有辅助软件(竟然有挂)-哔哩哔哩1、让任何用户在无需聚星a...
解迷透视!hardrock透视... 解迷透视!hardrock透视工具,wepoker透视苹果系统,总结教程(真是有挂)-哔哩哔哩在进入...