【发布时间】:2018-09-04 09:12:01
【问题描述】:
【问题讨论】:
标签: css angular angular-material
【问题讨论】:
标签: css angular angular-material
将<mat-chip>移出<mat-form-field></mat-form-field>
<div>
<mat-chip
*ngFor="let fruit of fruits"
[selectable]="selectable"
[removable]="removable"
(removed)="remove(fruit)">
{{fruit}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
</div>
请看这里:https://stackblitz.com/edit/angular-h8zdkh-ao3bzb?file=app/chips-autocomplete-example.html
【讨论】:
只需将input 字段移到</mat-chip-list> 之外(顶部或底部)就可以了。
您可能想在此之后添加一些填充/边距:)
【讨论】:
使用简单的auto-complete 搜索玩家并在外部div 中显示选定的玩家为chip-list,如下所示
<mat-form-field class="example-chip-list">
<input matInput placeholder="New fruit..." #fruitInput [formControl]="fruitCtrl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let fruit of filteredFruits | async" [value]="fruit">
{{fruit}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
<div class="otherDiv">
<mat-chip-list>
<mat-chip *ngFor="let fruit of fruits" [selectable]="selectable" [removable]="removable" (removed)="remove(fruit)">
{{fruit}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
</mat-chip-list>
</div>
【讨论】:
这很简单。 因为您已经在使用 fruits 数组来添加或删除项目, 因此,您可以在该组件的 html 文件中的任何位置访问 fruits 数组
【讨论】: