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

相关内容

热门资讯

解密关于!HH平台挂,hhpo... 解密关于!HH平台挂,hhpoker到底可以作弊码,真是真的是有挂(有挂方法)1、解密关于!HH平台...
三分钟了解!拱趴大菠萝怎么开挂... 三分钟了解!拱趴大菠萝怎么开挂,epoker透视底牌,竟然存在有挂(有挂总结)1、三分钟了解!拱趴大...
一分钟揭秘!aapoker能控... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
推荐一款!htx矩阵wepok... 推荐一款!htx矩阵wepoker辅助,德州之星扫描器,竟然真的有挂(有挂透明挂);进入游戏-大厅左...
热门推荐!德普之星app安卓版... 热门推荐!德普之星app安卓版破解版,pokemmo辅助脚本,竟然是真的有挂(讲解有挂)1、金币登录...
查到实测辅助!wejoker手... 查到实测辅助!wejoker手机版透视脚本,wepoker透视脚本安卓,确实是真的有挂(有挂秘诀);...
总算了解!wepoker养号规... 总算了解!wepoker养号规律,wepoker透视脚本是什么,好像真的有挂(讲解有挂)1、下载好透...
带你了解!wepoker破解游... 带你了解!wepoker破解游戏盒子,wepoker透视脚本免费,都是真的是有挂(今日头条)能透视中...
免费测试版!hhpoker的辅... 免费测试版!hhpoker的辅助是真的吗,哈糖大菠萝挂,原来存在有挂(有挂功能)所有人都在同一条线上...
今日公布!拱趴大菠萝挂,hhp... 今日公布!拱趴大菠萝挂,hhpoker作弊码,其实有挂(有挂方法)1、金币登录送、破产送、升级送、活...