[英]Angular Material mat-select - Showing count number along with the first selected value in multiple selection
In mat-select multiple selections, all the selected values are displayed in the select field.在 mat-select 多选中,所有选择的值都显示在选择字段中。 I want only the first selected value along with +1 or +2 etc if more than one value is selected.
如果选择了多个值,我只想要第一个选择的值以及 +1 或 +2 等。
You can use <mat-select-trigger>
to customize the displayed output of selected value(s).您可以使用
<mat-select-trigger>
自定义所选值的显示输出。
<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;
}
Sample Solution on StackBlitz StackBlitz 上的示例解决方案
Select |选择 | Angular Material (Section: Select with custom trigger text)
角度材质(部分:使用自定义触发文本选择)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.