What is the $$hashKey added to my JSON.stringify result What is the $$hashKey added to my JSON.stringify result json json

What is the $$hashKey added to my JSON.stringify result


Angular adds this to keep track of your changes, so it knows when it needs to update the DOM.

If you use angular.toJson(obj) instead of JSON.stringify(obj) then Angular will strip out these internal-use values for you.

Also, if you change your repeat expression to use the track by {uniqueProperty} suffix, Angular won't have to add $$hashKey at all. For example

<ul>    <li ng-repeat="link in navLinks track by link.href">        <a ng-href="link.href">{{link.title}}</a>    </li></ul>

Just always remember you need the "link." part of the expression - I always tend to forget that. Just track by href will surely not work.


In my use case (feeding the resulting object to X2JS) the recommended approach

data = angular.toJson(source);

help to remove the $$hashKey properties, but the result could then no longer be processed by X2JS.

data = angular.copy(source);

removed the $$hashKey properties as well, but the result remained usable as a parameter for X2JS.


It comes with the ng-repeat directive usually. To do dom manipulation AngularJS flags objects with special id.

This is common with Angular. For example if u get object with ngResource your object will embed all the resource API and you'll see methods like $save, etc. With cookies too AngularJS will add a property __ngDebug.