angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

angular.equals ignores keys with $ symbol in keys

Open samantp opened this issue 13 years ago • 7 comments

Hi,

I tried to use angular.compare while comparing ids returned by backend which unfortunately had the pattern _id = {$oid:"abcdefg.."}. Angular.equals returned true even though the $oid values were different.

Seems like keys with dollar are deliberately ignored. From code: if (key.charAt(0) === '$' || isFunction(o1[key])) continue;

Not sure whether this is the intended behavior.

Regards, --Parikshit N. Samant.

samantp avatar Oct 22 '13 14:10 samantp

most of the time, wouldn't objects with equal properties beginning with '$' typically have the same identity / reference the same object? Eg Scope.$id for instance -- I think it's not very common to use $ for properties in typical scenarios, though?

caitp avatar Oct 22 '13 16:10 caitp

Yes mostly. Just that in our case, we were getting back records stored in a MongoDB database where the web service converted the binary ObjectIDs to something like {$oid:'abcd'}. Maybe, even a note in the documentation regarding this behavior would be good enough.

samantp avatar Oct 23 '13 03:10 samantp

In fact, it looks like non-angular objects with $ need to be treated with care in general. For example, passing an object with a key starting with $ to http post/put requests also ends up sending an empty object to the server. The code in the angular function 'toJsonReplacer' sets it to undefined.

samantp avatar Oct 24 '13 11:10 samantp

I'm using '$' as an object property for use with Angular's filter to match a substring across all properties of my source array.

I want to set a watcher on that object so that I can repaginate a table after a filter is applied. But the watcher never fires because of this issue. I had to workaround it by using a function as my watchExpression rather than my object with the '$' property used by filter.

andrewbrown avatar Nov 21 '13 00:11 andrewbrown

Excuse me, how is this working as expected? I have the same problem, the watch ignores changes in my object on a field that has the name starting with '$'.

Since when all the fields starting with this symbol are reserved to Angular? This is a cop out. Can someone please reopen this case or do I need to create a new one?

MoonStorm avatar Mar 25 '15 15:03 MoonStorm

This was closed by btford. Not sure which version of Angular this works on.

samantp avatar Mar 28 '15 10:03 samantp

The ignoring of '$' prefixed keys also creates problems if comparing objects that will later be passed to MongoDB.

Would be nice to have an option to allow '$', or at least a note in the documentation.

peteboere avatar Jan 06 '16 13:01 peteboere