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

相关内容

热门资讯

今日头条!微扑克辅助挂多功能透... 今日头条!微扑克辅助挂多功能透视工具,本来存在有挂(有挂猫腻)1、微扑克辅助软件下载优化,微扑克底牌...
教学盘点!德普之星辅助挂多功能... 教学盘点!德普之星辅助挂多功能透视工具,真是是真的有挂(发现有挂)1、进入到德普之星是否有挂之后,能...
重大消息!aapoker辅助挂... 重大消息!aapoker辅助挂多功能透视工具,原来存在有挂(新版有挂)1、让任何用户在无需aapok...
终于懂了!WPK辅助挂多功能透... 终于懂了!WPK辅助挂多功能透视工具,好像存在有挂(详细教程)1、在WPK插件功能辅助器技巧中,中转...
实测交流!aapoker辅助挂... 实测交流!aapoker辅助挂多功能透视工具,确实真的是有挂(有挂规律)aapoker能透视中分为三...
推荐十款!微扑克辅助挂多功能透... 推荐十款!微扑克辅助挂多功能透视工具,总是是有挂(有挂分享)1、每一步都需要思考,不同水平的挑战会更...
查到实测!德扑之星辅助挂多功能... 查到实测!德扑之星辅助挂多功能透视工具,一直真的是有挂(新版有挂)1、该软件可以轻松地帮助玩家将德扑...
攻略讲解!德扑圈辅助挂多功能透... 攻略讲解!德扑圈辅助挂多功能透视工具,确实存在有挂(有挂技巧)1、玩家可以在德扑圈线上大神俱乐部对游...
一分钟揭秘!德扑圈辅助挂多功能... 一分钟揭秘!德扑圈辅助挂多功能透视工具,一贯真的是有挂(竟然有挂)1、进入到德扑圈是否有挂之后,能看...
一分钟了解!红龙poker辅助... 一分钟了解!红龙poker辅助挂多功能透视工具,总是是真的有挂(有挂总结)进入游戏-大厅左侧-新手福...