-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ng-model not binding <select> list values in 1.4.rc2 #11890
Comments
Is this a correct reproduction? http://plnkr.co/edit/k09Xh9xEgcXQBbKTkRdh So the select does not reflect the model? |
The reason for this is that in 1.4 we test for exact equality in the select directive. You can provide a simple directive to convert the value from number to string and back between the model and view: http://plnkr.co/edit/BnNkVENvNYyArbRjVaov?p=preview |
We should probably highlight this in the docs for |
While I think that this makes sense conceptually and probably for performance as well, I think this has a terrible usability aspect. I would imagine that this is a fairly common scenario that needs to be addressed and there's no intuitive discovery of this behavior until it fails. If you're new and starting out you're not going to make the connection that you have a type conversion problem. Even the solution of requiring a custom directive to make this work seems heavy handed. Shouldn't there be something built in to provide these types of conversions for you more easily without having to create a component? I don't want to derail this issue - the solution given is straight forward enough for me to fix and I can live with that. Thanks for pointing to the source of the issue and the solution! But I think in the grander scheme of things this should be thought over going forward (not sure how this will be handled in 2.0). |
We previously compared the model and attribute value with |
A more pernicious issue with using |
I updated the |
Thanks all. The docs and sample are definitely a good addition. |
I have a scenario that I am still unable to get to work, even with the directive: I have a set of enumerated values that I want to use for the options. It is unable to bind to get the initial value correctly, but if I put in the value directly for each enumerated value it works correctly. <select ng-model="vm.frameworkContext.frameworkViewType" convert-to-number>
<option value="{{vm.enums.FrameworkViewType.STATE_FRAMEWORK_ONLY}}">
State Framework Only
</option>
<option value="{{vm.enums.FrameworkViewType.INSTRUCTION_FRAMEWORK_ONLY}}">
Instructional Framework Only
</option>
<option value="{{vm.enums.FrameworkViewType.STATE_FRAMEWORK_DEFAULT}}">
State Framework Default
</option>
<option value="{{vm.enums.FrameworkViewType.INSTRUCTIONAL_FRAMEWORK_DEFAULT}}">
Instructional Framework Default
</option>
</select> where vm.enums.FrameworkViewType: {
UNDEFINED: 0,
STATE_FRAMEWORK_ONLY: 1,
STATE_FRAMEWORK_DEFAULT: 2,
INSTRUCTIONAL_FRAMEWORK_DEFAULT: 3,
INSTRUCTION_FRAMEWORK_ONLY: 4
} |
@annechinn, it seems to be working as expected. |
@annechinn I think your problem might be that option values are strings, while your enum values are integers. This is precisely the problem discussed here and now described in the |
I created the plunker and found that it is reproducible in 1.3, but fixed http://plnkr.co/edit/A5onypmeEm8xUzSDdpG1?p=preview On Wed, Oct 28, 2015 at 2:38 AM, Pete Bacon Darwin <notifications@github.com
|
@annechinn, the issue demonstrated in your plnkr is not the same (hence the I don't think such kind of bugs are getting fixed on |
I understand why === is much more better-er than ==, but this causes all sorts of issues when trying to bind to an object (as I am currently fighting with). We have an object barfing out as How about due to the new use of === and the fact that the right-hand side of this equation is always a string thanks to the HTML DOM, how about we force the left-hand side to be a string as well? Or at least give us the option to do so without some hack-y secondary directive (which I've still not gotten to work right in our case, by the way). |
@campbeln The value attribute in selects can only be a string, so when you have numbers you should use the ngOptions directive. Why the directive workaround doesn't work in your case is hard to say, but that's a question better asked on Stackoverflow etc. Lastly, if you have an idea how to improve the directive, opening a new issue is probably the better idea. |
@Narretz |
If ng Options doesn't bind satisfactorily please provide a minimal demo in a plnkr.co or similar and I'll have a look. |
Raised new issue here - #13955 You can't use |
I have a list of static values that are bound to a list and I'm trying to get the list to display the value from the model.
The model value is an integer:
Then in the html I'm binding this value to a dropdown list of static values:
This worked fine in v1.3 but in 1.4 the list comes back with no selection. Or, more specifically it has a selection of an injected element:
The text was updated successfully, but these errors were encountered: