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

fix(ngOptions): do not watch properties starting with $ #12010

Closed
wants to merge 1 commit into from

Conversation

petebacondarwin
Copy link
Member

Expressions that compute labels and track by values for ngOptions were
being called for properties, that start with $ even though those properties
were being ignored as options.

Closes #11930

Expressions that compute labels and track by values for ngOptions were
being called for properties, that start with $ even though those properties
were being ignored as options.

Closes angular#11930
@@ -303,6 +303,7 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) {
values = values || [];

Object.keys(values).forEach(function getWatchable(key) {
if (key.charAt(0) === '$') return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to ignore $ (and not just $$) properties ?
$$ are (by convention) private, but $ are (by convention again) Angular-specific, but not private.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gkalpak - good question. Right now we are ignoring such properties as options, so there is a precedent: https://github.com/angular/angular.js/blob/master/test/ng/directive/ngOptionsSpec.js#L434-L448

Also angular.equals and ngRepeat ignore single $ too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. For some reason, ToJsonReplacer() was modifed some time ago to only ignore $$ properties (but everything else (e.g. ngRepeat, ngOptions, equals) kept ignoring $ as well. Too much breaking change I guess :)

So, it's fine as it is 😃

@Narretz
Copy link
Contributor

Narretz commented Jun 3, 2015

LGTM

petebacondarwin added a commit that referenced this pull request Jun 24, 2015
It turns out that the options that are displayed are more constrained than
just whether the property starts with a $ character.
If the values collection is array-like then we only display the options that
are identified by numerical properties - it's an array right?

So this commit aligns `getWatchables` with `getOptions`.

See #12010
netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
Expressions that compute labels and track by values for ngOptions were
being called for properties, that start with $ even though those properties
were being ignored as options.

Closes angular#11930
Closes angular#12010
netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
It turns out that the options that are displayed are more constrained than
just whether the property starts with a $ character.
If the values collection is array-like then we only display the options that
are identified by numerical properties - it's an array right?

So this commit aligns `getWatchables` with `getOptions`.

See angular#12010
@petebacondarwin petebacondarwin deleted the issue-11930 branch November 24, 2016 09:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngOptions incorrectly evaluates label for $$hashKey when watching labels
3 participants