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

相关内容

热门资讯

透视挂!hhpoker透视工具... 透视挂!hhpoker透视工具(透视)确实真的是有挂(详细辅助存在挂教程);1、ai辅助优化,发牌逻...
玩家必看科普!hhpoker怎... 1、玩家必看科普!hhpoker怎么破解,aapoker ai插件,2025新版(有挂神器);详细教...
透视科技!hhpoker德州作... 透视科技!hhpoker德州作弊(透视)原来有挂(详细辅助2025新版教程);所有人都在同一条线上,...
科技新动态!wepoker怎么... 科技新动态!wepoker怎么开辅助,wpk显示有作弊,高科技教程(有挂透明),支持语音通讯、好友开...
透视辅助!约局吧德州真的有透视... 透视辅助!约局吧德州真的有透视挂吗(透视)其实真的是有挂(详细辅助微扑克教程)1、进入游戏-大厅左侧...
推荐一款!wepoker怎么设... 推荐一款!wepoker怎么设置盖牌,大菠萝辅助器,揭秘攻略(有挂辅助);支持多人共享记分板与复盘,...
透视攻略!wejoker内置辅... 透视攻略!wejoker内置辅助(透视)确实存在有挂(详细辅助AI教程)1、不需要AI权限,帮助你快...
一分钟带你了解!htx矩阵we... 一分钟带你了解!htx矩阵wepoker辅助,cloudpoker外挂,曝光教程(有挂神器)1、玩家...
透视数据!wepoker透视底... 透视数据!wepoker透视底牌脚本(透视)真是真的有挂(详细辅助科技教程)1、玩家可以在wepok...
分享开挂内幕!pokerwor... 分享开挂内幕!pokerworld辅助器,werplan透视挂,必备教程(有挂教程)1、玩家可以在p...