components icon indicating copy to clipboard operation
components copied to clipboard

md-select default value

Open Tytam opened this issue 9 years ago • 7 comments

Bug, feature request, or proposal:

When using formBuilder default value passed to formBuilder does not show as selected in md-select.

What is the expected behavior?

If I select value in formBuilder its name and value should appear as selected option of md-select.

What is the current behavior?

Placeholder is displayed instead.

What are the steps to reproduce?

typescript: this.editForm = this.formBuilder.group({ projectId: [this.task.project._id] }); or: this.editForm = this.formBuilder.group({ projectId: new FormControl({value: this.task.project._id}, Validators.required) });

html: <form layout="column" [formGroup]="editForm" (ngSubmit)="saveTask(task)"><md-select formControlName="projectId" name="project" placeholder="{{'FORM.PROJECT' | translate }}"><md-option *ngFor="let project of projects | async" [value]="project._id">{{project.name}}</md-option></md-select><select formControlName="projectId" name="project"><option *ngFor="let project of projects | async" [value]="project._id">{{project.name}}</option></select></form>

standard html works, md does't

What is the use-case or motivation for changing an existing behavior?

Edit forms. Lets have a class with 20 attributes each of them can be changed using one form. You don't want to refill all these attributes if you want to change just one.

Which versions of Angular, Material, OS, browsers are affected?

Angular 2.2.1 Material 2.0.0-beta.1 WIN 10 Vivaldi Firefox tested (but probably all affected)

Is there anything else we should know?

Tytam avatar Jan 23 '17 12:01 Tytam

Was about to raise a similar issue regarding the default value on md-select. The following does not set the default value of the select either: -

<md-select placeholder="Year" [(ngModel)]="selectedYear.Key" (change)="onYearSelect()"> <md-option *ngFor="let year of (yearsByCourse$|async)" [value]="year.Key"> {{ year.Description }} </md-option> </md-select>

When selectedYear.Key : -

this.selectedYear = { Key: '000116', Description: '16/17', CalendarYear: 2016 };

Works fine on a normal