0
votes

I am using mat select in angular 11. Can anyone help me out to show selected option in mat-select. I have a field named Idefault and a condition is, IF type.Idefault == true then show value as selected option in mat-select

Image is added for your reference

enter image description here

             <div class="col-sm-6 has-select pr-3">
                  <mat-form-field appearance="fill" class="pt-1 no-border">
                    <mat-select formControlName="source"  [(ngModel)]="selectedBatchSource" (selectionChange)="changeClient($event.value)" >
                      <mat-option *ngFor="let type of data$ | async"  [value]="type.ctype">
                        {{type.ctype}}
                      </mat-option>
                    </mat-select>
                  </mat-form-field>
                </div>
1
I'm not too familiar with the material api, but wouldn't you just predefine this.selectedBatchSource in your component to assign the default?Kinglish
Thanks for your response but here I want to show selected value when I opened a form. I used selectedBatchSource to get selected value from list when user select option from list.Ammad Amir

1 Answers

0
votes

 this.heroForm = new FormGroup({
    source: new FormControl('your default value here')
     
    ]),