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

相关内容

热门资讯

透视辅助"wepok... 透视辅助"wepoker插件辅助"其实是真的辅助软件(哔哩哔哩)1、下载好wepoker插件辅助脚本...
透视开挂"wepok... 透视开挂"wepoker透视版下载"本来是有辅助方法(哔哩哔哩);在进入wepoker透视版下载软件...
透视有挂"we-po... 透视有挂"we-poker辅助器"确实有辅助器(哔哩哔哩)1、任何we-poker辅助器透视是真的假...
透视了解"pokem... 透视了解"pokemomo辅助软件"总是是真的辅助挂(哔哩哔哩)1、pokemomo辅助软件有没有辅...
透视推荐"wepok... 透视推荐"wepoker辅助器安装包"其实有辅助教程(哔哩哔哩)所有人都在同一条线上,像星星一样排成...
透视揭露"wepok... 透视揭露"wepoker高级辅助"果然是真的辅助技巧(哔哩哔哩)wepoker高级辅助是不是有人用挂...
透视开挂"xpoke... 透视开挂"xpoker辅助工具"好像有辅助挂(哔哩哔哩)1、进入到xpoker辅助工具是否有挂之后,...
透视详细"德普之星有... 透视详细"德普之星有透视辅助吗"果然真的有辅助方法(哔哩哔哩)1、德普之星有透视辅助吗脚本辅助下载、...
透视关于"aapok... 透视关于"aapoker真的假的"竟然真的有辅助神器(哔哩哔哩)1、下载好aapoker真的假的脚本...
透视揭露"hh po... 透视揭露"hh poker透视器下载"果然存在有辅助方法(哔哩哔哩)1)hh poker透视器下载有...