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

相关内容

热门资讯

日前!潮友会pp下载辅助器,h... 日前!潮友会pp下载辅助器,hhpoker免费透视脚本,绝活教程(有挂讲解)-哔哩哔哩1、游戏颠覆性...
据报道!wepoker私局辅助... 据报道!wepoker私局辅助,hhpoker透视脚本视频(透视)科普教程(揭秘有挂)-哔哩哔哩一、...
透视插件!aapoker辅助插... 您好,aapoker辅助插件工具这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527505...
值得注意的是!科乐填大坑破解游... 值得注意的是!科乐填大坑破解游戏,九游破解辅助插件教程,绝活教程(有挂秘诀)-哔哩哔哩1、超多福利:...
最终!天天贵州万能辅助器,微乐... 最终!天天贵州万能辅助器,微乐智能辅助app,指南教程(有挂细节)-哔哩哔哩1、首先打开天天贵州万能...
透视神器!wepoker私人局... 透视神器!wepoker私人局透视插件,hhpkoer辅助器视频(透视)专业教程(真是有挂)-哔哩哔...
透视私人局!hhpoker怎么... 透视私人局!hhpoker怎么防辅助,werplan怎么透视(透视)科普教程(有挂解惑)-哔哩哔哩1...
无独有偶!微信微乐小程序辅助软... 无独有偶!微信微乐小程序辅助软件,epoker透视,攻略教程(有挂详情)-哔哩哔哩1、首先打开微信微...
截至发稿!we-poker有人... 截至发稿!we-poker有人玩吗,智星菠萝辅助(透视)解密教程(有挂助手)-哔哩哔哩所有人都在同一...
据报道!潮汕来物局透视脚本,w... 据报道!潮汕来物局透视脚本,wpk辅助插件,手筋教程(有挂总结)-哔哩哔哩一、潮汕来物局透视脚本可以...