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

相关内容

热门资讯

玩家亲测!圣游辅助器,wepo... 玩家亲测!圣游辅助器,wepokerplus作弊,透明挂教程(了解有挂);1、点击下载安装,圣游辅助...
一分钟了解!江西微乐南昌有辅助... 一分钟了解!江西微乐南昌有辅助,竞技联盟透视,攻略教程(了解有挂);江西微乐南昌有辅助最新软件透明挂...
一分钟了解!蜀山四川智能辅助插... 一分钟了解!蜀山四川智能辅助插件,hhpkoer辅助器,可靠教程(有挂规律);详细蜀山四川智能辅助插...
总算了解!新道游开挂辅助透视,... 总算了解!新道游开挂辅助透视,aapoker公共底牌,德州教程(有挂透明挂)是一款可以让一直输的玩家...
推荐一款!微乐小程序辅助收费,... 推荐一款!微乐小程序辅助收费,pokemmo脚本辅助器,2025教程(有人有挂);AI辅助机器人普及...
重磅来袭!大唐山西辅助软件,f... 重磅来袭!大唐山西辅助软件,fishpoker透视,可靠教程(证实有挂),大唐山西辅助软件是用手机号...
必备辅助推荐!广丰510k辅助... 必备辅助推荐!广丰510k辅助插件,wepoker游戏下载,德州论坛(讲解有挂)是一款可以让一直输的...
总算了解!小程序卡五星辅助,w... 总算了解!小程序卡五星辅助,wpk软件是正规的吗,AI教程(有挂存在);一、小程序卡五星辅助AI软件...
一分钟揭秘!孝感卡五星辅助,w... 一分钟揭秘!孝感卡五星辅助,wepoker有透视吗,必赢方法(有挂教学);1、让任何用户在无需AI插...
最新通报!悟空大厅辅助器,we... 最新通报!悟空大厅辅助器,we poker辅助器,详细教程(讲解有挂);悟空大厅辅助器软件透明挂是一...