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

相关内容

热门资讯

透视黑科技!红龙poker有辅... 透视黑科技!红龙poker有辅助吗,poker world辅助(透视)详细教程(有挂秘诀)-哔哩哔哩...
据监测!捉住捣蛋鸡透视,hhp... 据监测!捉住捣蛋鸡透视,hhpoker可以控制牌吗,模板教程(有挂辅助)-哔哩哔哩1、下载好hhpo...
透视了解!约局吧德州透视,德州... 透视了解!约局吧德州透视,德州局怎么透视(透视)曝光教程(竟然有挂)-哔哩哔哩1、上手简单,内置详细...
据权威媒体报道!凑一桌游戏辅助... 据权威媒体报道!凑一桌游戏辅助软件,超凡辅助下载,机巧教程(有挂讲解)-哔哩哔哩凑一桌游戏辅助软件辅...
透视神器!wepoker祈福有... 透视神器!wepoker祈福有用吗,wepokerplus脚本(透视)推荐教程(有挂头条)-哔哩哔哩...
围绕透视问题!微乐家乡小程序辅... 围绕透视问题!微乐家乡小程序辅助,新道游戏辅助器免费版,指南教程(真的有挂)-哔哩哔哩1、下载好新道...
透视了解!aa poker辅助... 透视了解!aa poker辅助,德普之星透视辅助软件(透视)解迷教程(真是有挂)-哔哩哔哩1、实时德...
有消息称!四川乐易麻将辅助脚本... 有消息称!四川乐易麻将辅助脚本,新上游辅助软件,法子教程(有挂秘笈)-哔哩哔哩1、操作简单,无需四川...
现场直击!wpk是真的还是假的... 现场直击!wpk是真的还是假的,sohoo开挂辅助(透视)揭幕教程(有挂攻略)-哔哩哔哩1)wpk是...
最终!赣牌圈破解器,微信小程序... 最终!赣牌圈破解器,微信小程序嘟嘟十三张脚本,技法教程(证实有挂)-哔哩哔哩1、该软件可以轻松地帮助...