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

相关内容

热门资讯

透视私人局"wepo... 透视私人局"wepoker私人局辅助器怎么用"详细辅助AI教程(果然是真的有挂)这是由厦门游乐互动科...
透视计算"wepok... 1、透视计算"wepoker软件靠谱么"详细辅助第三方教程(固有存在有挂);详细教程。2、wepok...
透视黑科技"wepo... 1、透视黑科技"wepoker破解是真的还是假的"详细辅助教你攻略(原生真的有挂)。2、wepoke...
透视透视"aa po... 透视透视"aa poker透视软件"详细辅助详细教程(一向真的是有挂);大神普及一款德州ai内幕,确...
透视透视"wepok... 这是一款非常优秀的wepokerplus透视脚本免费 ia辅助检测软件,能够让你了解到wepoker...
透视了解"xpoke... 透视了解"xpoker辅助工具"详细辅助安装教程(原生有挂);亲真的是有正版授权,小编(透视辅助软件...
透视线上"约局吧怎么... 透视线上"约局吧怎么看有没有挂"详细辅助透牌教程(竟然有挂);支持多人共享记分板与复盘,通过邀请好友...
透视透视"werpl... 透视透视"werplan脚本"详细辅助解密教程(一贯有挂);大神普及一款德州ai内幕,确定了werp...
透视规律"wepok... 透视规律"wepoker免费透视"详细辅助科技教程(固有真的是有挂)是一款可以让一直输的玩家,快速成...
透视苹果版"werp... 透视苹果版"werplan怎么作弊"详细辅助高科技教程(从前有挂);《WPK辅助透视》‌:支持手机实...