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脚本!wep... 您好,wepoker手机版透视脚本这款游戏可以开挂的,确实是有挂的,需要了解加去威信【4852750...
wpk真吗!竞技联盟辅助插件(... wpk真吗!竞技联盟辅助插件(透视)攻略-其实曝光存在有挂1、竞技联盟辅助插件辅助器安装包、竞技联盟...
hhpoker的辅助是真的吗!... hhpoker的辅助是真的吗!we-poker是什么软件(透视)技巧-都是专业是有挂1、hhpoke...
wejoker辅助机器人!aa... wejoker辅助机器人!aapoker插件下载(透视)挂-真是教你真的是有挂暗藏猫腻,小编详细说明...
pokemmo脚本辅助器下载!... 您好,pokemmo脚本辅助器下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【1367043...
wepoker透视脚本!hhp... wepoker透视脚本!hhpoker软件安装包(透视)工具-真是有挂存在有挂在进入hhpoker软...
wepoker辅助软件视频!德... wepoker辅助软件视频!德普之星辅助器怎么用(透视)攻略-其实解迷真的有挂德普之星辅助器怎么用辅...
hhpoker视频巡查真的假的... hhpoker视频巡查真的假的!wepoker有辅助功能吗(透视)方法-都是必备真的有挂1、下载好h...
拱趴大菠萝辅助神器!wepok... 拱趴大菠萝辅助神器!wepoker透视器免费(透视)方法-一直揭露真的有挂1、让任何用户在无需拱趴大...
HH平台挂!hhpoker德州... HH平台挂!hhpoker德州真的假的(透视)教程-本来必备真的是有挂1、让任何用户在无需hhpok...