In mat-select multiple selections, all the selected values are displayed in the select field. I want only the first selected value along with +1 or +2 etc if more than one value is selected.
Asked
Active
Viewed 1,639 times
2
-
Please provide enough code so others can better understand or reproduce the problem. – Community Oct 31 '21 at 12:02
1 Answers
3
You can use <mat-select-trigger>
to customize the displayed output of selected value(s).
<mat-select [formControl]="toppings" multiple>
<mat-select-trigger>
{{toppings.value ? toppings.value[0] : ''}}
<span *ngIf="toppings.value?.length > 1" class="example-additional-selection">
+{{toppings.value.length - 1}}
</span>
</mat-select-trigger>
<mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>
</mat-select>
.example-additional-selection {
opacity: 0.75;
font-size: 0.75em;
}
References
Select | Angular Material (Section: Select with custom trigger text)

Yong Shun
- 35,286
- 4
- 24
- 46