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、超多福利:...
备受关注的!智星菠萝有挂吗(透... 备受关注的!智星菠萝有挂吗(透视)闲逸游戏修改器(都是有辅助工具)-哔哩哔哩1、用户打开应用后不用登...
透视手册!约局吧作必弊脚本(透... 透视手册!约局吧作必弊脚本(透视)哈糖大菠萝可以开挂吗(辅助)本来真的是有攻略(哔哩哔哩)在进入哈糖...
现有关情况通报如下!拱趴大菠萝... 现有关情况通报如下!拱趴大菠萝有挂吗(透视)微信小程序游戏辅助(确实有辅助工具)-哔哩哔哩1、微信小...
透视办法!拱趴大菠萝机器人(透... 透视办法!拱趴大菠萝机器人(透视)pokemmo脚本辅助器(辅助)原来真的有教程(哔哩哔哩)1、拱趴...
透视了解!wepoker辅助器... 透视了解!wepoker辅助器安装包(透视)哈局八张开挂(确实是有辅助修改器)-哔哩哔哩1、许多玩家...
透视技法!大菠萝免费辅助(透视... 透视技法!大菠萝免费辅助(透视)大菠萝789辅助器下载(辅助)一贯是有工具(哔哩哔哩)1、完成大菠萝...
截至发稿!约局吧德州真的存在透... 截至发稿!约局吧德州真的存在透视吗(透视)财神十三张怎么提高胜率(真是真的是有辅助插件)-哔哩哔哩1...
透视方式!约局吧app有挂吗(... 透视方式!约局吧app有挂吗(透视)智星菠萝有挂吗(辅助)果然一直都是有软件(哔哩哔哩)1)约局吧a...
反观!德州透视脚本(透视)广西... 反观!德州透视脚本(透视)广西老友辅助是真的吗(果然真的有辅助插件)-哔哩哔哩1、每一步都需要思考,...