I have created a form, I am using angular material and I can successfully get and set the value in text feild or in textarea field but not able to put a value in a dropdown, I have two json data. First will fill the dropdown and after that second one will set the value of dropdown. So onload page I have to display that value on the dropdown which is not getting set
createProductForm(): FormGroup {
return this._formBuilder.group({
CATEGORY: [this.product.categories]
});
}
ngOnInit() {
getAllCategory=[
{"TYPE_CODE": "CATEGORY","TYPE_DESC": "PUBLIC"},
{"TYPE_CODE": "CATEGORY","TYPE_DESC": "PRIVATE"},
{"TYPE_CODE": "CATEGORY","TYPE_DESC": "SYSTEM"},
]
defaultSelectCategory=[
{"CATEGORY": "PRIVATE"}
]
this.defaultCat= defaultSelectCategory[0].CATEGORY;
}
<mat-form-field appearance="outline" fxFlex="100">
<mat-label>Project</mat-label>
<mat-select formControlName="CATEGORY" [(value)]="defaultCat" required >
<mat-option *ngFor="let item of getAllCategory" value="{{item.TYPE_DESC}}" (onSelectionChange)="getCATEGORY(item)">
{{item.TYPE_DESC}}
</mat-option>
</mat-select>
<mat-icon matSuffix class="secondary-text">outlined_flag</mat-icon>
</mat-form-field>
don't know somehow I am not able to set a default value to dropdown Onload. thank you so much. and btw today is my birthday so don't forget to wish me. lol