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

Bug: md-select doesn't set selected value if options are initialized after the model #2497

Closed
shedar opened this issue Jan 2, 2017 · 3 comments · Fixed by #2499
Closed
Assignees

Comments

@shedar
Copy link

shedar commented Jan 2, 2017

Bug, feature request, or proposal:

Bug, if ngModel of md-select is set before setting of options - select doesn't show selected value after both (options and model) are set.

What is the expected behavior?

Showing selected value after both (model and options) are set.

What is the current behavior?

Selected value is shown if options are set before ngModel value, otherwise selected value is not shown.

What are the steps to reproduce?

http://plnkr.co/edit/yL8QJBjABGPRerqGIR2b?p=preview

You see two selects, left one shows selected value, right one - doesn't.

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

For ajax loaded value and options the order of initialization is not guaranteed. Without fixing this bug you need to add an additional logic to the app to init select value only after options array is set.

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

Tested with Angular 2.4.1, Angular material 2.0.0-beta.1.

Is there anything else we should know?

@shedar shedar changed the title Bug: md-select don't set selected value if options are initialized after the model Bug: md-select doesn't set selected value if options are initialized after the model Jan 2, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 2, 2017
…dded asynchronously

Fixes the select component not highlighting the model value when the options get added after initialization.

Fixes angular#2497.
@crisbeto crisbeto added the has pr label Jan 2, 2017
@drPavka
Copy link

drPavka commented Jan 12, 2017

Is there any way to apply this patch crisbeto@2f2cc8e to the project
until it will be merged to production branch?

@shedar
Copy link
Author

shedar commented Jan 12, 2017

@drPavka as a workaround you can add something like *ngIf="options && options.length" to your md-select. This way component would not be initialized until options are ready.

crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 12, 2017
…dded asynchronously

Fixes the select component not highlighting the model value when the options get added after initialization.

Fixes angular#2497.
tinayuangao pushed a commit that referenced this issue Jan 13, 2017
…dded asynchronously (#2499)

* fix(select): selected option not being highlighted when options are added asynchronously

Fixes the select component not highlighting the model value when the options get added after initialization.

Fixes #2497.

* Address the feedback.

* Fix linter errors.
@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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants