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)佛手大菠萝有挂吗免...
开挂透视!智星菠萝有挂吗,微乐... 开挂透视!智星菠萝有挂吗,微乐自建房脚本最新版本更新内容,教程书教程(有人有挂)-哔哩哔哩进入游戏-...
普及透视!wepokerplu... 普及透视!wepokerplus透视脚本免费,微信小程序微乐破解器,要领教程(有挂工具)-哔哩哔哩1...
解谜透视!wepoker开辅助... 解谜透视!wepoker开辅助能查到吗,微信微乐小程序有窍门吗,举措教程(有挂细节)-哔哩哔哩1)w...
推荐透视!佛手在线是不是有挂,... 推荐透视!佛手在线是不是有挂,万能透视辅助器免费版,窍门教程(竟然有挂)-哔哩哔哩1、玩家可以在佛手...
总结透视!wpk辅助器是真的吗... 总结透视!wpk辅助器是真的吗,微乐贵阳麻将辅助,窍门教程(有挂猫腻)-哔哩哔哩1、wpk辅助器是真...
解谜透视!poker worl... 解谜透视!poker world辅助,微乐多乐跑作弊,练习教程(有挂方略)-哔哩哔哩1、poker ...
了解透视!wpk插件,微乐四川... 了解透视!wpk插件,微乐四川小程序修改器,演示教程(了解有挂)-哔哩哔哩1、操作简单,无需wpk插...
开挂透视!hh poker软件... 开挂透视!hh poker软件,微乐陕西小程序破解器,方案教程(证实有挂)-哔哩哔哩1、金币登录送、...
关于透视!aapoker透视脚... 关于透视!aapoker透视脚本下载,微信小程序游戏破解器,积累教程(有人有挂)-哔哩哔哩1、完成a...