首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在角度输入中添加mat选择

如何在角度输入中添加mat选择
EN

Stack Overflow用户
提问于 2020-06-17 01:04:55
回答 1查看 4.6K关注 0票数 1

我发现要在我的输入字段中添加mat select,但由于某种原因,当我单击箭头时,它不起作用,并且没有显示所有列表。

我有自动补全功能,通常当用户开始输入时,会显示所有要选择的列表,但我正在尝试添加mat-select,这样用户就可以单击箭头并从列表中进行选择,而不必先输入一些内容。

我遵循了下面的stackblitz示例(我的不需要复选框),但我的略有不同,我也有文本输入和自动完成功能,所以我不确定为什么我不能再用当前代码输入,而且当我单击箭头时,下拉列表也不显示。

任何建议或帮助都会得到真正的重视。

https://stackblitz.com/edit/angular-material-v9-mat-select-with-mat-chip-list?file=src%2Fapp%2Fselect-multiple-example.html

代码语言:javascript
运行
复制
    <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>

EN

Stack Overflow用户

发布于 2020-06-17 01:22:56

在这种情况下,我不会使用芯片列表和自动完成的组合。

我认为,您真正需要的是包含多选复选框的自动完成功能。试着这样做,就像这样。

代码语言:javascript
运行
复制
<mat-form-field class="example-full-width">
    <input type="text" placeholder="Select Users" aria-label="Select Users" matInput [matAutocomplete]="auto" [formControl]="userControl">
  <mat-hint>Enter text to find users by name</mat-hint>
</mat-form-field>

<mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
    <mat-option *ngFor="let user of filteredUsers | async" [value]="selectedUsers">
        <div (click)="optionClicked($event, user)">
            <mat-checkbox [checked]="user.selected" (change)="toggleSelection(user)" (click)="$event.stopPropagation()">
                {{ user.firstname }} {{ user.lastname }}
            </mat-checkbox>
        </div>
    </mat-option>
</mat-autocomplete>

完整示例:

https://stackblitz.com/edit/angular-sx79hu?embed=1&file=app/multiselect-autocomplete-example.html

票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62413876

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档