Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

selected select option not updating when model change #10939

Closed
KthProg opened this issue Feb 2, 2015 · 7 comments
Closed

selected select option not updating when model change #10939

KthProg opened this issue Feb 2, 2015 · 7 comments

Comments

@KthProg
Copy link

KthProg commented Feb 2, 2015

Plunker: http://plnkr.co/edit/U0N3VzU1CCb5LZuevBX3?p=preview

Version: 1.3.0-beta.18

The basics are:

3 selects

select 1 is the parent of select 2
select 2 is the parent of select 3

select 1 -> select 2 -> select 3

when select 1's value changes, the options for select 2 change, and are fetched asynchronously.
when select 2's value changes, the options for select 3 change, and are fetched asynchronously.

these asynchronous updates are accomplished using several $watch()es.

$watch("select 1", function(n){
[select 2].getOptions(n);
});

$watch("select 2", function(n){
[select 3].getOptions(n);
});

all the selects have values before their options change

the options for each select look like this:
[{k: 0, v : 'a'},
{k: 2, v: 'c'},
{k: 3, v: 'b'},
... etc.]

select 1's displayed option is correct
select 2's, 3's, 4's, etc. displayed option is NOT correct (it just displays the first option in the list)

the model value matches one of the option values, however that option is not displayed.

@KthProg KthProg changed the title select options not updating selected select option not updating when value changes Feb 2, 2015
@KthProg KthProg changed the title selected select option not updating when value changes selected select option not updating when model changes Feb 2, 2015
@Narretz
Copy link
Contributor

Narretz commented Feb 3, 2015

Without a reproduction, there's very littel we can do about this. Also, which version of angular are you using?

@KthProg
Copy link
Author

KthProg commented Feb 3, 2015

Here's a basic plunker showing the issue:

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

In the plunker, only the first selected option is correct.

It very clearly shows a disconnect between the model and the view, despite a digest cycle having run.

All other information is in my edited initial post.

@frfancha
Copy link

frfancha commented Feb 3, 2015

There is a big refactoring of ng-options in 1.4, I was curious to try 1.4.0-beta.2 in the plunker.
With this version the lists stay empty...

@KthProg KthProg changed the title selected select option not updating when model changes PLEASE LOOK I ADDED MORE INFO Feb 4, 2015
@Narretz Narretz changed the title PLEASE LOOK I ADDED MORE INFO selected select option not updating when model change Feb 4, 2015
@Narretz
Copy link
Contributor

Narretz commented Feb 4, 2015

With a title like this, you are only so very slightly increasing your chances that somebody looks at this. Please understand that this is an open source project and our time is limited.

This seems like a valid issue, though.

@Narretz Narretz modified the milestones: 1.4.x, Purgatory Feb 4, 2015
@Narretz
Copy link
Contributor

Narretz commented Feb 4, 2015

Well, actually, the documentation for select notes specifically that ngOptions instead of repeated option elements should be used when the model is bound to a non-string value (like in your case, value is an integer).
Have you tried the same with ngOptions?

@KthProg
Copy link
Author

KthProg commented Feb 4, 2015

Wow. I found the problem. The data coming off of the server for the options is a string, but the value is a number. I needed to format the option values as numbers. That and using ng-options (as in the now-working plunker) fixed the issue.

ng-options did fix the issue. In my app and in the production code.
It was basically a non-issue. Thank you.

@KthProg KthProg closed this as completed Feb 4, 2015
@boyfunky
Copy link

i have the code in my angularjs - ionic project but on iOS9 upon clicking on selecting from the dropdownlist , it doesn't bind to the model unless the user clicks somewhere else.

State

wht is wrong wt the code why wouldn't it bind to the model when selected. This happens only on ios9.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants