Skip to content

Commit

Permalink
fix(ngOptions): iterate over the options collection in the same way a…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
petebacondarwin committed Apr 30, 2015
1 parent 77fcfb3 commit bf74c72
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/ng/directive/ngOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,6 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {

for (var index = 0; index < optionValuesLength; index++) {
var key = (optionValues === optionValuesKeys) ? index : optionValuesKeys[index];

// Ignore "angular" properties that start with $ or $$
if (key.charAt && key.charAt(0) === '$') return;

var value = optionValues[key];
var locals = getLocals(value, key);
var viewValue = viewValueFn(scope, locals);
Expand Down

0 comments on commit bf74c72

Please sign in to comment.