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

Select not set to ngModel initial value #4854

Closed
doorman02 opened this issue May 28, 2017 · 5 comments · Fixed by #4868
Closed

Select not set to ngModel initial value #4854

doorman02 opened this issue May 28, 2017 · 5 comments · Fixed by #4868
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@doorman02
Copy link

Bug, feature request, or proposal:

When setting the ngModel variable in code behind onInit the selected display value is not showing.
This works in beta 5 but not anymore in beta 6

What is the expected behavior?

The select should show the display string of the ngModel value

What is the current behavior?

It does not show anything

What are the steps to reproduce?

<md-select [(ngModel)]="selectedSortBy " mdTooltip="Sort by">
              <md-option [value]="0">Latest</md-option>
              <md-option [value]="1">Highest</md-option>
              <md-option [value]="2">Lowest</md-option>
            </md-select>

and in component file onInit setting
selectedSortBy= 0;
does not display Latest

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

Select should show the databound value

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

Material beta.6 latest angular

Is there anything else we should know?

@julianobrasil
Copy link
Contributor

julianobrasil commented May 28, 2017

That's weird, because if you set selectedSortBy='0' (string) it works in any of two ways:

<md-option value="0">Latest</md-option>

or

<md-option [value]="'0'">Latest</md-option>

But both of them fail with numbers.

niveo referenced this issue May 29, 2017
…tion (#3141)

* fix(select): allow option with undefined or null value to clear selection

Allows for options, with a value of `null` or `undefined`, to clear the select. This is similar to the way the native select works.

Fixes #3110.
Fixes #2634.

* fix: address feedback
@willshowell
Copy link
Contributor

willshowell commented May 29, 2017

Looks like the offending line is here:

// _selectValue()

optionsArray.find(option => option.value && option.value === value);

A value of 0 is falsey for option.value

@crisbeto crisbeto self-assigned this May 29, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue May 29, 2017
Fixes not being able to set falsy values progammatically in `md-select`.

Fixes angular#4854.
@vohtaski
Copy link

Any idea when it will be merged?

@kara kara added the P2 The issue is important to a large percentage of users, with a workaround label May 30, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue May 31, 2017
Fixes not being able to set falsy values progammatically in `md-select`.

Fixes angular#4854.
@robindijkhof
Copy link
Contributor

Not sure if it will be usefull, but here is a pluker: https://plnkr.co/edit/UURJWRfiglafS8KkOjRt?p=preview

@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
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants