【发布时间】:2020-10-06 09:06:15
【问题描述】:
我正在寻找在我的输入字段上添加 mat select 但由于某种原因,当我单击箭头时,它不起作用并且没有向我显示所有列表。
我有自动完成功能,通常当用户开始输入时会显示所有要选择的列表,但我也在尝试添加 mat-select 以便用户只需单击箭头并从列表中选择,而无需先输入内容.
我遵循了下面的 stackblitz 示例(我的不需要复选框),但我的有点不同,我也有文本输入和自动完成,所以我不知道为什么我不能再输入我的输入单击箭头时,当前代码和下拉列表均未显示。
任何建议或帮助都会受到赞赏。
<mat-form-field class="form" appearance="fill">
<mat-label>Search or Select a Super Tag</mat-label>
<mat-select [formControl]="superTags" multiple>
<mat-select-trigger>
<mat-chip-list #chipList>
<div>
<mat-chip *ngFor="let superTag of superTags" [selectable]="selectable" [removable]="removable"
(removed)="remove(superTag)">
<img class="super-icon" src="/assets/images/icons/super-tag-icon.svg">
{{superTag.tag}}
<mat-icon matChipRemove *ngIf="removable" matTooltip="Remove a super tag">cancel</mat-icon>
</mat-chip>
</div>
<div>
<input matInput #input [(ngModel)]="tagIn" [formControl]="tagCtrl" [matAutocomplete]="auto" [matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" (matChipInputTokenEnd)="addTag()">
</div>
</mat-chip-list>
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngIf="isLoading" class="is-Loading">
<mat-spinner diameter="20"></mat-spinner>
</mat-option>
<ng-container *ngIf="!isLoading">
<mat-option *ngFor="let tag of filteredSuperTags | async" [value]="tag">
{{tag}}
</mat-option>
</ng-container>
</mat-autocomplete>
</mat-select-trigger>
</mat-select>
</mat-form-field>
【问题讨论】:
-
尝试 ng-select 库ng-select.github.io/ng-select#/data-sources
标签: html css angular angular-material html-select