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

相关内容

热门资讯

记者揭秘!pokemmo脚本(... 记者揭秘!pokemmo脚本(辅助挂)原来真的是有挂(有挂详细)1、pokemmo脚本免费辅助多个强...
实测分享!wepoker透视有... 实测分享!wepoker透视有没有(辅助挂)确实真的有挂(今日头条)1、实测分享!wepoker透视...
一分钟揭秘!poker红龙辅助... 一分钟揭秘!poker红龙辅助(辅助挂)其实有挂(有挂讲解);1)poker红龙辅助有没有挂:进一步...
推荐十款!如何下载wpk透视版... 推荐十款!如何下载wpk透视版(辅助挂)一贯是真的有挂(真的有挂)如何下载wpk透视版是不是有人用挂...
必知教程!破解辅助插件wepo... 必知教程!破解辅助插件wepoker(辅助挂)好像是真的有挂(有挂方法);暗藏猫腻,小编详细说明破解...
玩家必看!德州真人透视脚本(辅... 玩家必看!德州真人透视脚本(辅助挂)好像存在有挂(有挂秘笈)1、德州真人透视脚本公共底牌简单,德州真...
技巧知识分享!pokermas... 技巧知识分享!pokermaster破解版(辅助挂)果然真的是有挂(有挂细节)1、上手简单,内置详细...
我来教大家!wepoker作弊... 我来教大家!wepoker作弊辅助(辅助挂)本来真的有挂(有挂攻略)1、全新机制【wepoker作弊...
玩家爆料!wpk免费辅助(辅助... 玩家爆料!wpk免费辅助(辅助挂)竟然是真的有挂(有挂解惑)1、进入到wpk免费辅助是否有挂之后,能...
推荐十款!wepoker轻量版... 推荐十款!wepoker轻量版透视方法(辅助挂)好像真的是有挂(真实有挂)1)wepoker轻量版透...