-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ng-options include array properties #11733
Comments
You mean props starting with |
Functions as well, yielding some very bizarre |
If it is of any help: Please take a look at this fiddle: Open the extended Array drop-down (SELECT), you will see all sorts of things like functions, length, etc. This was not happening until Angular 1.3. https://jsfiddle.net/superasn/k2uwdjh5/ (working fine) |
Thanks, this is helpful. (although both your fiddles have 1.4.0-rc.1. You can also use plnkr.co, where it's simpler to switch dependencies) |
Sorry about that.. I've updated the second fiddle, please try it here: |
This is a bug. Let's fix it.
What do you think should happen in each of these cases? |
My somewhat fast and cheap answer would be "the same as |
ng-repeat doesn't deal with non-arraylike objects anymore |
wait I'm wrong, it totally still does. how did we not get rid of that yet |
…s `ngRepeat` In `ngRepeat` if the object to be iterated over is "array-like" then it only iterates over the numerical indexes rather than every key on the object. This prevents "helper" methods from being included in the rendered collection. This commit changes `ngOptions` to iterate in the same way. BREAKING CHANGE: Although it is unlikely that anyone is using it in this way, this change does change the behaviour of `ngOptions` in the following case: * you are iterating over an array-like object, using the array form of the `ngOptions` syntax (`item.label for item in items`) and that object contains non-numeric property keys. In this case these properties with non-numeric keys will be ignored. ** Here array-like is defined by the result of a call to this internal function: https://github.com/angular/angular.js/blob/v1.4.0-rc.1/src/Angular.js#L198-L211 ** To get the desired behaviour you need to iterate using the object form of the `ngOptions` syntax (`value.label` for (key, value) in items)`). Closes angular#11733
Here is a fix (#11771) that makes There is a tiny breaking change. @Narretz & @caitp what do you think - is that too big a BC to get it into 1.4.0? |
…s `ngRepeat` In `ngRepeat` if the object to be iterated over is "array-like" then it only iterates over the numerical indexes rather than every key on the object. This prevents "helper" methods from being included in the rendered collection. This commit changes `ngOptions` to iterate in the same way. BREAKING CHANGE: Although it is unlikely that anyone is using it in this way, this change does change the behaviour of `ngOptions` in the following case: * you are iterating over an array-like object, using the array form of the `ngOptions` syntax (`item.label for item in items`) and that object contains non-numeric property keys. In this case these properties with non-numeric keys will be ignored. ** Here array-like is defined by the result of a call to this internal function: https://github.com/angular/angular.js/blob/v1.4.0-rc.1/src/Angular.js#L198-L211 ** To get the desired behaviour you need to iterate using the object form of the `ngOptions` syntax (`value.label` for (key, value) in items)`). Closes angular#11733
Breaking Change is okay, as there's a pretty simple workaround. And it doesn't affect many people. |
Yes, that would be great. For example, filterFilter also doesn't work with Array like objects anymore, like it used to before. Please take a look at this fiddle: Works like it should with previous version of Angular (v1.2): Breaks with newer versions of Angular (v1.3 and above): |
@petebacondarwin i have created a new issue here: |
…s `ngRepeat` In `ngRepeat` if the object to be iterated over is "array-like" then it only iterates over the numerical indexes rather than every key on the object. This prevents "helper" methods from being included in the rendered collection. This commit changes `ngOptions` to iterate in the same way. BREAKING CHANGE: Although it is unlikely that anyone is using it in this way, this change does change the behaviour of `ngOptions` in the following case: * you are iterating over an array-like object, using the array form of the `ngOptions` syntax (`item.label for item in items`) and that object contains non-numeric property keys. In this case these properties with non-numeric keys will be ignored. ** Here array-like is defined by the result of a call to this internal function: https://github.com/angular/angular.js/blob/v1.4.0-rc.1/src/Angular.js#L198-L211 ** To get the desired behaviour you need to iterate using the object form of the `ngOptions` syntax (`value.label` for (key, value) in items)`). Closes angular#11733
If an array contains additional properties (notably, as when fetched with Restangular, which adds several functions to the array), these extra properties are included in the iteration for ng-options, leading to unexpected "junk" entries in the select dropdown.
This differs from the iteration when using ng-repeat over the same array, which does not include such properties.
(This is new behavior in v1.4 rc0 and rc1. v1.3 does not show this behavior)
The text was updated successfully, but these errors were encountered: