Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

md-select default value #2762

Closed
Tytam opened this issue Jan 23, 2017 · 7 comments
Closed

md-select default value #2762

Tytam opened this issue Jan 23, 2017 · 7 comments

Comments

@Tytam
Copy link

Tytam commented Jan 23, 2017

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?

@asbcoder
Copy link

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 . Maybe raise this as seperate issue?

@Tytam
Copy link
Author

Tytam commented Jan 24, 2017

Somehow my code now works (we made mayor backend changes). So my issue bay be caused by angular 2 meteor I use and not material problem. If I find out something new I write a comment here.

@kara
Copy link
Contributor

kara commented Jan 24, 2017

@Tytam Given that your code now works, I'm going to close this for now. Feel free to open a new issue if you run into anything else.

@asbcoder It sounds like you may have run into #2497, which was fixed in #2499. It's in master, but not yet released. If you're still having problems after the next release, please open an issue.

@kara kara closed this as completed Jan 24, 2017
@jeewanaryal2012
Copy link

Please open this issue, I am having the same issue now. The default value does not show up, it shows the placeholder instead.

@peterramsing
Copy link

I've run into this before with numbers and it was because our types misaligned. Worth making sure your types are correct if one runs into this.

@kailash-cd
Copy link

kailash-cd commented Nov 28, 2018

Facing same issue in following --
<md-select
placeholder="Choose your country"
[(ngModel)]="selectedCountries"
multiple searchable
class="infoRow2 input-container" >

<input
mdInput
ngClass="{{companyTheme+'_themeInput'}}"
[(ngModel)]="countryFilterKey"
type="search"
placeholder="Search Country">

        <md-option
          ngClass="{{companyTheme+'_themeSelectOption'}}"
          *ngFor="let country of countryOptions | filter: {'name':countryFilterKey} "
          [value]="country"
          (click)="updateCountries(country)">
          {{ country.name }}
        </md-option>
      </md-select>

default value --
selectedCountries = [
{'code': 'JA', 'name': 'Japan', 'center': [36.204824,138.252924]},
{'code': 'US', 'name': 'United States', 'center': [37.2566274, -95.712891]}
];

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants