'How to display a value in mat-select without being inside mat-option?
In my case I'm using a formcontrolName
with the mat-select
. I would like to display a value on the mat-select
, but not inside the dropdown list of options :
<mat-select #objet formControlName="cars" >
<mat-option *ngFor="let f of listCars" [value]="f">{{f.name}}</mat-option>
</mat-select>
Thanks for helping!
Solution 1:[1]
<mat-select #objet formControlName="cars" >
<mat-option *ngFor="let f of listCars" [value]="f">{{f.name}}</mat-option>
</mat-select>
<div>{{ myForm.get("cars")?.value }}</div>
Solution 2:[2]
<mat-select #objet formControlName="cars" [placeholder]="value || 'Label shown if empty' ">
<mat-option *ngFor="let f of listCars" [value]="f">{{f.name}}</mat-option>
</mat-select>
The placeholder attribute will show a default value in the mat-select but not in the dropdown.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | O.MeeKoh |
Solution 2 | Yassine CHABLI |