2
votes

I have a mat-select in my form with multiple options (You can see a demo in here).

<mat-form-field style="width: 100%">
  <mat-select placeholder="Toppings" [formControl]="toppings" multiple>
    <mat-option *ngFor="let topping of toppingList" [value]="topping">{{topping}}</mat-option>
  </mat-select>
</mat-form-field>

It shows a comma-separated list of selected options in its input field. Is there any way to change the separator?

1
Code is missing. Please make your question a Minimal, Complete, and Verifiable example M.C.V E. Also check how to ask question to make your post answerable.Morse

1 Answers

5
votes

The code that is responsible for that separator could be found here https://github.com/angular/material2/blob/9f6aa843cd2f68562d3f5290688bbe5bab957bcf/src/lib/select/select.ts#L642

// TODO(crisbeto): delimiter should be configurable for proper localization.
return selectedOptions.join(', ');

As you can see it is not supported yet. But there is another way to achieve it.

Just add custom mat-select-trigger as below:

<mat-select [formControl]="toppings" multiple ...>
    ...
    <mat-select-trigger>
        <span> {{toppings.value ? toppings.value.join('; ') : ''}}</span>
    </mat-select-trigger>
</mat-select>

Forked Demo

So that you can choose any separator, for example:

toppings.value.join('&#9832;')

enter image description here