components icon indicating copy to clipboard operation
components copied to clipboard

[selected] property for mat-option element

Open costea93 opened this issue 8 years ago • 9 comments

This is just an question or it might be an improvement.

I have this select component, and try select default an option from ngFor with [selected] property

      `<mat-form-field>
            <mat-select (change)="onSelect($event.target.value, question)">
                <mat-option>{{'select' | translate}}</mat-option>
                <mat-option *ngFor="let option of question.questionOptions"
                            [selected]="option.selected"
                            [value]="option.value">{{option.value}}</mat-option>
            </mat-select>
        </mat-form-field>`

but that won't work because mat-option doesn't have [selected] property. I know that i should add [selected] property to mat-select, but why not to have it to mat-option?

costea93 avatar Feb 09 '18 10:02 costea93

i have the same problem @costea93 have you save this?

hellojukay avatar Mar 06 '18 06:03 hellojukay

<mat-select [(value)]="selectedCode" formControlName="StatusCode">
       <mat-option *ngFor="let status of statuses" [value]="status.Value" >
              {{ status.Value }}
       </mat-option>
</mat-select>`

Where selectedCode is selected object in statuses list, pay attention to [value] for mat-option

sanidz avatar Jul 12 '18 10:07 sanidz

@sanidz this does not work

gags88 avatar Aug 01 '18 15:08 gags88

Sure? https://angular-hk47fh.stackblitz.io

https://stackblitz.com/edit/angular-hk47fh?file=app/select-overview-example.ts

sanidz avatar Aug 02 '18 10:08 sanidz

Конечно? https://angular-hk47fh.stackblitz.io

https://stackblitz.com/edit/angular-hk47fh?file=app/select-overview-example.ts

how to make multiple advance selection?

free-soldier28 avatar Sep 21 '18 05:09 free-soldier28

Конечно? https://angular-hk47fh.stackblitz.io https://stackblitz.com/edit/angular-hk47fh?file=app/select-overview-example.ts

how to make multiple advance selection?

Not sure what do you mean by that, in dropdown only one element can be selected. If you want to do multiple selection, maybe check lists could do the trick. Could you explain your usecase in more details?

sanidz avatar Sep 21 '18 06:09 sanidz

I want to set <mat-select multiple> one option to default checked.

Anzil-Aufait avatar May 21 '19 12:05 Anzil-Aufait

The [value] attribute seems to only work if you're not using the formControlName directive. Currently facing the same issue. I have to manually use contol.setValue(value) in the component to update the view.

Shiroh1ge avatar May 25 '19 20:05 Shiroh1ge

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.