https://github.com/bithost-gmbh/ngx-mat-select-search
这是一个Angular组件,为Angular Material库的MatSelect选项提供一个输入字段用于搜索/过滤。
<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/ffb36202-5719-49fc-a20b-67e63a138f27.png" alt="示例" width="293"/>在以下链接可以看到实际效果:
https://stackblitz.com/github/bithost-gmbh/ngx-mat-select-search-example
查看示例代码,在浏览器中构建,最新版本,最新Material版本
https://bithost-gmbh.github.io/ngx-mat-select-search/
预构建,最新版本,较旧的Material版本,可在移动设备上运行
重要提示:本项目是https://github.com/angular/material2/issues/5697的临时实现。 最终目标是在官方Angular Material仓库中实现,将创建一个新的PR。
欢迎贡献,请开启一个issue,最好提交一个pull request。
我们致力于通过不断改进NgxMatSelectSearch并快速响应错误报告来提供最佳服务。我们完全免费提供这些服务。
如果您觉得这个库对您有用,为您和您的业务节省了宝贵的时间,请考虑捐赠以支持其维护和进一步开发。
非常感谢我们的财务支持者!
<!-- readme: pschulzk,sponsors -start --> <table> <tr> <td align="center"> <a href="https://github.com/pschulzk"> <img src="https://avatars.githubusercontent.com/u/7001048?v=4" width="100;" alt="pschulzk"/> <br /> <sub><b>Philip Viktor Schulz-Klingauf</b></sub> </a> </td></tr> </table> <!-- readme: pschulzk,sponsors -end -->非常感谢我们所有的社区贡献者!
<!-- readme: contributors -start --> <table> <tr> <td align="center"> <a href="https://github.com/macjohnny"> <img src="https://avatars.githubusercontent.com/u/5589029?v=4" width="100;" alt="macjohnny"/> <br /> <sub><b>Esteban Gehring</b></sub> </a> </td> <td align="center"> <a href="https://github.com/maechler"> <img src="https://avatars.githubusercontent.com/u/4113819?v=4" width="100;" alt="maechler"/> <br /> <sub><b>Markus Mächler</b></sub> </a> </td> <td align="center"> <a href="https://github.com/angelaki"> <img src="https://avatars.githubusercontent.com/u/38611461?v=4" width="100;" alt="angelaki"/> <br /> <sub><b>Tristan</b></sub> </a> </td> <td align="center"> <a href="https://github.com/tonyholt"> <img src="https://avatars.githubusercontent.com/u/893926?v=4" width="100;" alt="tonyholt"/> <br /> <sub><b>Tony H</b></sub> </a> </td> <td align="center"> <a href="https://github.com/mstawick"> <img src="https://avatars.githubusercontent.com/u/1216844?v=4" width="100;" alt="mstawick"/> <br /> <sub><b>Michał Stawicki</b></sub> </a> </td> <td align="center"> <a href="https://github.com/alexandrupaul7"> <img src="https://avatars.githubusercontent.com/u/28051061?v=4" width="100;" alt="alexandrupaul7"/> <br /> <sub><b>Null</b></sub> </a> </td></tr> <tr> <td align="center"> <a href="https://github.com/blazewalker59"> <img src="https://avatars.githubusercontent.com/u/21110755?v=4" width="100;" alt="blazewalker59"/> <br /> <sub><b>Blaze Walker</b></sub> </a> </td> <td align="center"> <a href="https://github.com/achilehero"> <img src="https://avatars.githubusercontent.com/u/14956052?v=4" width="100;" alt="achilehero"/> <br /> <sub><b>Cristian Raducanu</b></sub> </a> </td> <td align="center"> <a href="https://github.com/damianmigo"> <img src="https://avatars.githubusercontent.com/u/1733403?v=4" width="100;" alt="damianmigo"/> <br /> <sub><b>Damian Miranda</b></sub> </a> </td> <td align="center"> <a href="https://github.com/Danevandy99"> <img src="https://avatars.githubusercontent.com/u/13788320?v=4" width="100;" alt="Danevandy99"/> <br /> <sub><b>Dane Vanderbilt</b></sub> </a> </td> <td align="center"> <a href="https://github.com/escheiermann"> <img src="https://avatars.githubusercontent.com/u/39056343?v=4" width="100;" alt="escheiermann"/> <br /> <sub><b>Edgar Scheiermann</b></sub> </a> </td> <td align="center"> <a href="https://github.com/arucar"> <img src="https://avatars.githubusercontent.com/u/37804893?v=4" width="100;" alt="arucar"/> <br /> <sub><b>Erendis</b></sub> </a> </td></tr> <tr> <td align="center"> <a href="https://github.com/gustavovitor"> <img src="https://avatars.githubusercontent.com/u/37344068?v=4" width="100;" alt="gustavovitor"/> <br /> <sub><b>Gustavo Miranda</b></sub> </a> </td> <td align="center"> <a href="https://github.com/meta72"> <img src="https://avatars.githubusercontent.com/u/3915589?v=4" width="100;" alt="meta72"/> <br /> <sub><b>Henno Lauinger</b></sub> </a> </td> <td align="center"> <a href="https://github.com/himanshu-singh1995"> <img src="https://avatars.githubusercontent.com/u/29891513?v=4" width="100;" alt="himanshu-singh1995"/> <br /> <sub><b>空</b></sub> </a> </td> <td align="center"> <a href="https://github.com/jfcere"> <img src="https://avatars.githubusercontent.com/u/6987084?v=4" width="100;" alt="jfcere"/> <br /> <sub><b>Jean-Francois Cere</b></sub> </a> </td> <td align="center"> <a href="https://github.com/josephdecock"> <img src="https://avatars.githubusercontent.com/u/1145533?v=4" width="100;" alt="josephdecock"/> <br /> <sub><b>Joe DeCock</b></sub> </a> </td> <td align="center"> <a href="https://github.com/JomalJohny"> <img src="https://avatars.githubusercontent.com/u/43292719?v=4" width="100;" alt="JomalJohny"/> <br /> <sub><b>Jomal Johny</b></sub> </a> </td></tr> <tr> <td align="center"> <a href="https://github.com/bulldog98"> <img src="https://avatars.githubusercontent.com/u/314259?v=4" width="100;" alt="bulldog98"/> <br /> <sub><b>Jonathan Kolberg</b></sub> </a> </td> <td align="center"> <a href="https://github.com/melroy89"> <img src="https://avatars.githubusercontent.com/u/628926?v=4" width="100;" alt="melroy89"/> <br /> <sub><b>Melroy Van Den Berg</b></sub> </a> </td> <td align="center"> <a href="https://github.com/AhsanAyaz"> <img src="https://avatars.githubusercontent.com/u/9844254?v=4" width="100;" alt="AhsanAyaz"/> <br /> <sub><b>Muhammad Ahsan Ayaz</b></sub> </a> </td> <td align="center"> <a href="https://github.com/OvidijusStukas"> <img src="https://avatars.githubusercontent.com/u/9720553?v=4" width="100;" alt="OvidijusStukas"/> <br /> <sub><b>Ovidijus Stukas</b></sub> </a> </td> <td align="center"> <a href="https://github.com/qstiegler"> <img src="https://avatars.githubusercontent.com/u/2858579?v=4" width="100;" alt="qstiegler"/> <br /> <sub><b>Quirin Stiegler</b></sub> </a> </td> <td align="center"> <a href="https://github.com/raysuelzer"> <img src="https://avatars.githubusercontent.com/u/1176341?v=4" width="100;" alt="raysuelzer"/> <br /> <sub><b>Ray Suelzer</b></sub> </a> </td></tr> <tr> <td align="center"> <a href="https://github.com/probert94"> <img src="https://avatars.githubusercontent.com/u/18258317?v=4" width="100;" alt="probert94"/> <br /> <sub><b>Robert Pattis</b></sub> </a> </td> <td align="center"> <a href="https://github.com/broekema41"> <img src="https://avatars.githubusercontent.com/u/4007585?v=4" width="100;" alt="broekema41"/> <br /> <sub><b>Roland Broekema</b></sub> </a> </td> <td align="center"> <a href="https://github.com/swierzbicki"> <img src="https://avatars.githubusercontent.com/u/7196324?v=4" width="100;" alt="swierzbicki"/> <br /> <sub><b>Sebastian Wierzbicki </b></sub> </a> </td> <td align="center"> <a href="https://github.com/shenay-aydan"> <img src="https://avatars.githubusercontent.com/u/38660036?v=4" width="100;" alt="shenay-aydan"/> <br /> <sub><b>空</b></sub> </a> </td> <td align="center"> <a href="https://github.com/framasev"> <img src="https://avatars.githubusercontent.com/u/41595972?v=4" width="100;" alt="framasev"/> <br /> <sub><b>Stas Amasev</b></sub> </a> </td> <td align="center"> <a href="https://github.com/nischi"> <img src="https://avatars.githubusercontent.com/u/2036054?v=4" width="100;" alt="nischi"/> <br /> <sub><b>Thierry Nischelwitzer</b></sub> </a> </td></tr> <tr> <td align="center"> <a href="https://github.com/vlio20"> <img src="https://avatars.githubusercontent.com/u/4542641?v=4" width="100;" alt="vlio20"/> <br /> <sub><b>Vlad Ioffe</b></sub> </a> </td> <td align="center"> <a href="https://github.com/WX9yMOXWId"> <img src="https://avatars.githubusercontent.com/u/30053114?v=4" width="100;" alt="WX9yMOXWId"/> <br /> <sub><b>无</b></sub> </a> </td> <td align="center"> <a href="https://github.com/zpaynter"> <img src="https://avatars.githubusercontent.com/u/29746771?v=4" width="100;" alt="zpaynter"/> <br /> <sub><b>无</b></sub> </a> </td> <td align="center"> <a href="https://github.com/evoltafreak"> <img src="https://avatars.githubusercontent.com/u/11610680?v=4" width="100;" alt="evoltafreak"/> <br /> <sub><b>Joshua</b></sub> </a> </td> <td align="center"> <a href="https://github.com/lorenzbaier"> <img src="https://avatars.githubusercontent.com/u/64407215?v=4" width="100;" alt="lorenzbaier"/> <br /> <sub><b>无</b></sub> </a> </td> <td align="center"> <a href="https://github.com/ruekart"> <img src="https://avatars.githubusercontent.com/u/9154610?v=4" width="100;" alt="ruekart"/> <br /> <sub><b>无</b></sub> </a> </td></tr> </table> <!-- readme: contributors -end --> ## 如何使用?在您的项目中安装 ngx-mat-select-search:
npm install ngx-mat-select-search
在您的 app.module.ts 中导入 NgxMatSelectSearchModule:
import { MatSelectModule } from '@angular/material'; import { NgxMatSelectSearchModule } from 'ngx-mat-select-search'; @NgModule({ imports: [ ... MatSelectModule, NgxMatSelectSearchModule ], }) export class AppModule {}
通过将 ngx-mat-select-search 组件放置在 <mat-option> 元素内,在 mat-select 元素中使用它:
<mat-form-field> <mat-select [formControl]="bankCtrl" placeholder="银行" #singleSelect> <mat-option> <ngx-mat-select-search [formControl]="bankFilterCtrl"></ngx-mat-select-search> </mat-option> <mat-option *ngFor="let bank of filteredBanks | async" [value]="bank"> {{bank.name}} </mat-option> </mat-select> </mat-form-field>
查看 https://github.com/bithost-gmbh/ngx-mat-select-search/tree/master/src/app/examples 中的示例,了解如何连接 ngx-mat-select-search 并过滤可用选项。
或者查看 https://github.com/bithost-gmbh/ngx-mat-select-search-example 以在独立应用中查看它。
您也可以在模板驱动表单中使用它,如下所示:
<ngx-mat-select-search ngModel (ngModelChange)="filterMyOptions($event)">
要更改标签,请使用 API 部分中指定的输入,如下所示:
<ngx-mat-select-search [formControl]="bankFilterCtrl" placeholderLabel="查找银行..." noEntriesFoundLabel="未找到匹配的银 行"></ngx-mat-select-search>
要使用 i18n API 进行标签翻译,请添加相应的 i18n-... 属性:
<ngx-mat-select-search [formControl]="bankFilterCtrl" placeholderLabel="查找银行..." i18n-placeholderLabel noEntriesFoundLabel="未找到匹配的银行" i18n-noEntriesFoundLabel></ngx-mat-select-search>
@angular/core: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0@angular/material: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 与 MatSelectModule (@angular/material/select)6.0.0@angular/core: ^15.0.0@angular/material: ^15.0.0 与 MatLegacySelectModule (@angular/material/legacy-select)5.0.0@angular/core: ^12.0.0 || ^13.0.0 || ^14.0.0@angular/material: ^12.0.0 || ^13.0.0 || ^14.0.03.3.3@angular/core: ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0@angular/material: ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.01.8.0@angular/core: ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0@angular/material: ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0MatSelectSearchComponent 实现了 ControlValueAccessor 接口。
此外,它还提供以下输入:
/** 搜索占位符的标签 */ @Input() placeholderLabel = '搜索'; /** 搜索输入字段的类型 */ @Input() type = 'text'; /** 用于显示关闭图标的基于字体的图标 */ @Input() closeIcon = 'close'; /** 用于显示关闭图标的基于SVG的图标。如果设置,将覆盖closeIcon */ @Input() closeSvgIcon?: string;
/** 当未找到条目时显示的标签。如果不应显示消息,则设置为 null。 */ @Input() noEntriesFoundLabel = '未找到选项';
/**
/** 是否显示搜索进行中的指示器 */ @Input() searching = false;
/** 禁用输入字段的初始聚焦 */ @Input() disableInitialFocus = false;
/** 启用按 Esc 键清除输入 */ @Input() enableClearOnEscapePressed = false;
/**
/** 当选项列表变化时禁用滚动到活动选项。对服务器端搜索很有用 */ @Input() disableScrollToActiveOnOptionsChanged = false;
/** 为搜索框添加 508 屏幕阅读器支持 */ @Input() ariaLabel = '下拉搜索';
/** 是否显示全选复选框(适用于 mat-select[multi=true]) */ @Input() showToggleAllCheckbox = false;
/** 全选复选框选中状态 */ @Input() toggleAllCheckboxChecked = false;
/** 全选复选框不确定状态 */ @Input() toggleAllCheckboxIndeterminate = false;
/** 在全选复选框的工具提示中显示消息 */ @Input() toggleAllCheckboxTooltipMessage = '';
/** 定义全选复选框工具提示的位置 */ @Input() toggleAllCheckboxTooltipPosition: 'left' | 'right' | 'above' | 'below' | 'before' | 'after' = 'below';
/** 显示/隐藏搜索输入的清除按钮 */ @Input() hideClearSearchButton = false;
/**
/** 输出事件发射器,用于向父组件发送全选布尔值 */ @Output() toggleAll = new EventEmitter<boolean>();
#### 自定义清除图标
为了自定义搜索图标,将 `ngxMatSelectSearchClear` 添加到您的自定义清除项(一个 `mat-icon` 或任何其他元素)并将其放置在 `ngx-mat-select-search` 组件内:
```html
<ngx-mat-select-search>
<mat-icon ngxMatSelectSearchClear>delete</mat-icon>
</ngx-mat-select-search>
如果只需要更改图标,可以使用 closeIcon 和 closeSvgIcon 输入。
为了自定义未找到条目元素,将 ngxMatSelectNoEntriesFound 添加到您的自定义项(一个 mat-icon、span、button 或任何其他元素)并将其放置在 ngx-mat-select-search 组件内:
<ngx-mat-select-search> <span ngxMatSelectNoEntriesFound> 未找到条目 <button mat-button color="primary"> 添加 <mat-icon>add</mat-icon> </button> </span> </ngx-mat-select-search>
带有 CSS 类 mat-select-search-custom-header-content 的自定义内容可以如下嵌入:
<ngx-mat-select-search> <div class="mat-select-search-custom-header-content">特殊内容</div> </ngx-mat-select-search>
通过提供 MAT_SELECTSEARCH_DEFAULT_OPTIONS
注入令牌,可以全局设置 MatSelectSearchComponent 的多个 @Input() 属性的默认值。
请参阅 MatSelectSearchComponent 中相应 @Input() 属性的文档。
示例:
import { MAT_SELECTSEARCH_DEFAULT_OPTIONS, MatSelectSearchOptions } from 'ngx-mat-select-search'; @NgModule({ ... providers: [ { provide: MAT_SELECTSEARCH_DEFAULT_OPTIONS, useValue: <MatSelectSearchOptions>{ closeIcon: 'delete', noEntriesFoundLabel: '未找到选项', } } ] }) class AppModule {}
本项目使用 Angular CLI 版本 1.7.1 生成。
运行 ng serve 启动开发服务器。导航到 http://localhost:4200/。如果您更改任何源文件,应用程序将自动重新加载。
运行 ng build 构建项目。构建产物将存储在 dist/ 目录中。使用 -prod 标志进行生产构建。
运行 npm run build-lib 构建库并生成 NPM 包。
构建产物将存储在 dist-lib/ 文件夹中。
运行 npm run test 通过 Karma 执行单元测试。


职场AI,就用扣子
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!


多风格AI绘画神器
堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。


零代码AI应用开发平台
零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。


免费创建高清无水印Sora视频
Vora是一个免费创建高清无水印Sora视频的AI工具


最适合小白的AI自动化工作流平台
无需编码,轻松生成可复用、可变现的AI自动化工作流

大模型驱动的Excel数据处理工具
基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


AI论文写作指导平台
AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。


AI一键生成PPT,就用博思AIPPT!
博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。


AI赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号