html - 我如何在 Angular Material 选择表单组件中添加搜索功能?

标签 html angular typescript angular-material-6

我有来自 Angular Material 的 mat-select 下拉列表。
它有来自API的状态列表。它在下拉列表中有 10 多个选项。

待办事项:

  • 我想要搜索选项 在 mat-select 中。我使用了 stackblitz 的 mat-select search 但它真的很难理解。

请给我一些简单的方法。

我的json代码

"{
  "data": [
    {
      "id": 32,
      "name": "Andaman And Nicobar Islands"
    },
    {
      "id": 16,
      "name": "Odisha"
    },
    {
      "id": 34,
      "name": "Puducherry"
    },
    {
      "id": 19,
      "name": "Uttar Pradesh"
    },
    {
      "id": 5,
      "name": "Uttarakhand"
    },
    {
      "id": 6,
      "name": "Andhra Pradesh"
    }
  ],
  "statusCode": 200
}"

最佳答案

<mat-select-search [formControl]="formControlName"></mat-select-search>

在 mat-select 中添加此标签并按照 StackBlitz 的 app.component.ts 中的步骤进行操作

关于html - 我如何在 Angular Material 选择表单组件中添加搜索功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55332588/

相关文章:

javascript - 在 Angular 4 上使用 Chart.js

node.js - 尚未为模型 "ResourceSchema"注册架构。 - 巢.js

Typescript Enum Object.values() 返回值

typescript - 类与接口(interface)作为 typescript 中的类型

Jquery 使一个 Div 成为可点击的表单区域

html - 为什么我的导航栏不起作用?

angular - 更改 Kendo UI Angular 2 上的日期过滤器格式

javascript - PHP Ajax 不工作

javascript - 在选择框 onchange 上运行 chrome.cookies.set

css - 在 Angular 中将通用 CSS 放在哪里