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

相关内容

热门资讯

透视线上"hardr... 透视线上"hardrock透视工具"详细辅助教你教程(透视底牌神器);亲真的是有正版授权,小编(透视...
透视玄学"hhpok... 透视玄学"hhpoker真能买到挂吗"详细辅助AI教程(辅助机器人技巧)1、很好的工具软件,可以解锁...
透视美元局"竞技联盟... 透视美元局"竞技联盟透视插件"详细辅助细节揭秘(有辅助器技巧)准备好在竞技联盟透视插件ia的高塔上攀...
透视攻略"hhpok... 透视攻略"hhpoker是真的假的"详细辅助wpk教程(可以设置透视软件);人气非常高,ai更新快且...
透视免费"wepok... 1、透视免费"wepoker轻量版透视"详细辅助2025教程(私人局开挂视频软件);详细教程。2、w...
透视新版"wepok... 自定义wepoker手机版辅助系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助...
透视黑科技"wepo... 透视黑科技"wepoker的辅助器"详细辅助透牌教程(可以设置房间透明);致您一封信;亲爱wepok...
透视系统"wepok... 透视系统"wepoker好友局透视"详细辅助透明挂教程(私人局辅助教程)是一款可以让一直输的玩家,快...
透视游戏"大菠萝免费... 透视游戏"大菠萝免费辅助器"详细辅助安装教程(透视脚本安卓神器);最新版2024是一款经典耐玩的益智...
透视ai"wepok... 透视ai"wepoker国外版透视"详细辅助2025新版总结(透视方法攻略);建议优先通过wepok...