issue case in stackblitz
Problem:
How to achieve that the mat-chips
in angular-material are in one line (as they are as standard), but when looped via ngFor
in a mat-chip-list
(which is inside a mat-cell
), they get placed all on a seperate line (see column "Name").
Goal: I would like to have it in line next to each until break due to width limit (see column "Weight").
chips of comma seprated string elements of name (e.g. A, Z) should be next to each other on line:
const ELEMENT_DATA: PeriodicElement[] = [
{position: 1, name: 'A, Z', weight: 1.0079, symbol: 'H'},
{position: 2, name: 'this first, this second in line', weight: 4.0026, symbol: 'He'},
];
as in
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element">
<mat-chip-list class="no-wrap" *ngFor="let n of element.name.split(',')">
<span class="nobreak">
<mat-chip class="no-wrap">{{n}}</mat-chip>
</span>
</mat-chip-list>
</td>
</ng-container>
visualisation issue case with angular-material
Selection. Chips can be selected via the selected property. Selection can be disabled by setting selectable to false on the <mat-chip-list> .
The md-contact-chips, an Angular Directive, is an input control built on md-chips and uses the md-autocomplete element. The contact chip component accepts a query expression which returns a list of possible contacts. The user can select one of these and add it to the list of availble chips.
Your *ngFor
is on the wrong tag, you have to place it on your <mat-chip>
, see below :
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element">
<mat-chip-list class="no-wrap" >
<mat-chip class="no-wrap" *ngFor="let n of element.name.split(',')">{{n}}</mat-chip>
</mat-chip-list>
</td>
</ng-container>
With your code you create a mat-chip-list
for each element
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With