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

select chooses wrong option when ng:repeat used inside select #639

Closed
esprehn opened this issue Nov 5, 2011 · 3 comments
Closed

select chooses wrong option when ng:repeat used inside select #639

esprehn opened this issue Nov 5, 2011 · 3 comments

Comments

@esprehn
Copy link
Contributor

esprehn commented Nov 5, 2011

will show the first element as selected, even though the ng:model bound value is different. If you interact with the select and start selecting values to change the bound value it will become resynchronized with the model. http://jsfiddle.net/GTynf/3/ Verified in both Webkit and Firefox, this isn't browser specific.

@IgorMinar
Copy link
Contributor

This is why ng:options exists in the first place. For months we tried to get ng:repeat to work within the select element, but we could never get it right and all the hacks we needed to create an illusion of this working were really polluting the angular code base.

I'd go as far as throwing an exception when you try to use ng:repeat on an option element, but in some simple cases, the current behavior is good enough.

The whole thing comes down to issues like the repeater unrolling too late and select trying to pick an option too early. There was some other stuff as well that I can't remember now.

@sweisman
Copy link

This is old but still seems to be a problem. I am now using 1.0.2 and am having this exact same problem.

I have this:

<select name="license_year" ng-options="license_year for license_year in license_year_list" ng-model="item.license_year"></select>

license_year_list is just a plain array (eg): [1990, 1991, 1992, ...]

I know the binding works, because when I select a year, item.license_year is updated. But when the select list is first displayed, no value is selected, even though there is an option for the value of item.license_year. The exact same behavior as esprehn, and I am using ng-options, exactly like you say!

Do I need to generate the options explicitly and then mark the initial selected option?

@jeffbcross
Copy link
Contributor

Closing this issue, as the problem no longer exists when using ngOptions.

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