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有辅助吗,hhpoker作弊实战视频,确实真的有挂(确实有挂)1、该软件可以...
信息共享!红龙poker辅助,... 信息共享!红龙poker辅助,pokemmo脚本辅助下载,本来存在有挂(有挂分析)1. 选牌创建新账...
科技新动态!红龙poker作弊... 科技新动态!红龙poker作弊指令,来玩德州破解器,果然真的是有挂(有挂教程)1、玩家可以在透视最简...
六分钟了解!wepoker数据... 六分钟了解!wepoker数据分析,wpk免费辅助,本来真的有挂(有挂秘笈)运辅助工具,进入游戏界面...
新手必备!wepoker怎么破... 新手必备!wepoker怎么破解游戏,拱趴大菠萝挂怎么安装,真是真的有挂(有挂助手)1、拱趴大菠萝挂...
详细说明!aapoker万能辅... 详细说明!aapoker万能辅助器,wepoker透视苹果系统,原来是真的有挂(真的有挂)1、脚本辅...
记者揭秘!大菠萝手游辅助,拱趴... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
程序员教你!werplan外卦... 程序员教你!werplan外卦神器,hhpoker外挂靠谱吗,一直真的有挂(有挂解惑)1、每一步都需...
每日必看!wepoker数据分... 每日必看!wepoker数据分析,wpk免费辅助,都是是有挂(有挂辅助)1、该软件可以轻松地帮助玩家...
一分钟教你!德普之星有透视辅助... 一分钟教你!德普之星有透视辅助吗,微扑克数据分析,一直有挂(有挂实锤)暗藏猫腻,小编详细说明破解器有...