angular.equals ignores keys with $ symbol in keys
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.
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?
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.
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.
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.
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?
This was closed by btford. Not sure which version of Angular this works on.
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.