In my Angular 7 app I'am using the component mat-select of angular material in a reactive form.
The view looks like this :
<mat-form-field class="col-md-3" color="warn">
<mat-select placeholder="Selectionner la boutique"
id="libelleShop"
[(value)]="selectedlibelleShopoValue"
ngDefaultControl
formControlName="libelleShop"
(selectionChange)="onShopSelectionChanged($event)">
<mat-option *ngFor="let shop of shopsList"
[value]="shop">
{{shop.storeName}}
</mat-option>
</mat-select>
Md data is the following :
shopsList= [
{
'edoId': '2119',
'storeName': 'AIX LES BAINS'
},
{
'edoId': '2123',
'storeName': 'ANNEMASSE'
},
{
'edoId': '2460',
'storeName': 'ALENCON'
},
{
'edoId': '2478',
'storeName': 'Grand Evreux Carrefour'
},
{
'edoId': '2632',
'storeName': 'DESTRELAND'
}
]
After the first loading , the options apperead in the select dropdown successfully, and I have a button used to force the value of the mat-select when clicked.
I have tried this:
onClick(){
let shopObjToDisplay = {};
shopObjToDisplay['edoId'] = '2460';
shopObjToDisplay['storeName'] = 'ALENCON';
this.myForm.patchValue({'libelleShop': shopObjToDisplay });
}
Unfortenately it seems that my data is not set.
Any ideas??
this.myForm.patchValue({'libelleShop': shopObjToDisplay.storeName });? - GCSDCshopListthat you have bound to yourmat-select. Try:this.myForm.patchValue({'libelleShop': this.shopList[2] });- Fabian Küng