$$hashKey

15,059 views
Skip to first unread message

Guiboy

unread,
Nov 7, 2011, 7:03:46 PM11/7/11
to AngularJS
I am seeing $$hashKey on allot of my objects, is this coming from
angular? i have to remove this from my objects so i don't send them
with my json.

Igor Minar

unread,
Nov 8, 2011, 1:19:52 AM11/8/11
to ang...@googlegroups.com
yes, it comes from ng:repeat which in order to do stable dom manipulation has to mark objects with special $$hashKey id.

however you should never see this stuff on the server side if you are using angular.toJson, $xhr or $resource services. How is your data being serialized?

/i


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


Guiboy

unread,
Nov 11, 2011, 12:20:20 AM11/11/11
to AngularJS
I am using jquery.couch to send the data to a couchapp it uses xhr
internally to send the data, i am manipulating my object and sending
it with the jquery.couch.saveDoc(....) , but since i am not using
$resource or $xhr, i need to manually strip my objects of this $
$hashKey, any ideas?

Marcello Nuccio

unread,
Nov 11, 2011, 5:25:22 AM11/11/11
to ang...@googlegroups.com
Hi Guiboy, I'm using AngularJS with CouchDB. I've found that it's very easy to use the CouchDB HTTP API directly through the $resource service. So, if you have not already done it, I suggest that you try it.

Marcello

Misko Hevery

unread,
Nov 11, 2011, 9:35:12 AM11/11/11
to ang...@googlegroups.com
angular.toJson should do the stripping for you.

On Fri, Nov 11, 2011 at 2:25 AM, Marcello Nuccio <marcell...@gmail.com> wrote:
Hi Guiboy, I'm using AngularJS with CouchDB. I've found that it's very easy to use the CouchDB HTTP API directly through the $resource service. So, if you have not already done it, I suggest that you try it.

Marcello

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/-8UyF5bYiUIJ.

Guiboy

unread,
Nov 11, 2011, 10:55:12 AM11/11/11
to AngularJS
Marcelo, perhaps you could share your CUD implementation?, i saw
the potential on $resource but it was not completely clear for me how
to use it, then i settled for jquery.couch on my couchapp.

cheers

--gui--

Marcello Nuccio

unread,
Nov 11, 2011, 11:31:38 AM11/11/11
to ang...@googlegroups.com
Sure, but be warned: I'm a Javascript and AngularJS newbie...

  // Setup the $xhr.error service to alert() errors.
  // Change it to fit your application!
  angular.service('$xhr.error', function () {
    return function (request, response) {
      var msg, body;
      if (response) {
        body = response.body;
        msg = 'ERROR ' + response.status + ': ' + (typeof body !== 'string' ? JSON.stringify(body) : body);
      } else {
        msg = 'REQUEST FAILED: ' + JSON.stringify(request);
      }
      alert(msg);
    };
  }, { $eager: true });

  // Service for getting documents:
  angular.service('Document', function ($resource) {
    return $resource('/db/:id', { id: '@_id' }, {
      query: {
        method: 'GET',
        isArray: false,
        params: {
          id: '_all_docs',
          include_docs: 'true'
        }
      },
      save: { method: 'PUT' }
    });
  }, { $inject: ['$resource'] });


Then you can get a document with:

  var doc = Document.get({ id: 'DOCID' });

You can save it with any of:

  doc.$save();
  Document.save(doc);

Hope it helps,
  Marcello

Guiboy

unread,
Nov 12, 2011, 12:39:23 AM11/12/11
to AngularJS
thanks, will look into this asap

Marcello Nuccio

unread,
Nov 12, 2011, 4:25:52 AM11/12/11
to ang...@googlegroups.com
I forgot to mention two things:
  1. Due to bug #545 you cannot use AngularJS 0.9.19: use 0.10.5 or build latest 0.9.x from sources.
  2. The query method in the example Document service is for querying _all_docs, e.g.:
  Document.query({ startkey: 'SOMEKEY', endkey: 'OTHERKEY' });

Marcello

Igor Minar

unread,
Nov 12, 2011, 9:18:03 PM11/12/11
to ang...@googlegroups.com
Thanks Marcello.

We appreciate all your activity on the issue tracker and mailing list. Can we send you a t-shirt as a sign of our gratitude?

Please fill out: http://goo.gl/D9uOx

/i





Marcello

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/7a0DtqtfClwJ.

barnabas...@gmail.com

unread,
Nov 20, 2012, 2:27:04 PM11/20/12
to ang...@googlegroups.com
For anyone who might come across this issue again, it seems that angular.copy strips out $$hashKey from your objects.

So rather than: 
scope.$emit($scope.myArray)

You could do:
scope.$emit(angular.copy($scope.myArray))

And voila! No $$hashKey. 

Benny Lichtner

unread,
Dec 27, 2012, 2:53:18 AM12/27/12
to ang...@googlegroups.com, barnabas...@gmail.com
Hmm. Are you sure? angular.copy doesn't seem to do this for me.

Sergey Gurevich

unread,
Mar 26, 2013, 4:04:34 PM3/26/13
to ang...@googlegroups.com
Hi!

Here! use this:

$scope.ngObjFixHack = function(ngObj) {
    var output;

    output = angular.toJson(ngObj);
    output = angular.fromJson(output);

    return output;
}

This also fixes angularJS issue where ng-repeat was not effected by order changes due to $$hashKey.

I came up with it when sorting an object (slice) didn't effect HTML display of mg-repeat.


Cheers

Tomáš Reichmann

unread,
Aug 15, 2014, 7:10:27 AM8/15/14
to ang...@googlegroups.com
Hi guys, 

I used the example of 3 way data binding from Angular website. I also experience the $$hashKey error while updating.

Where do I strip the $$hashKey?

var ref = new Firebase("https://profile-web.firebaseio.com/");
// create an AngularFire reference to the data
var sync = $firebase(ref);
// download the data into a local object
var syncObject = sync.$asObject();
// synchronize the object with a three-way data binding
// click on `index.html` above to see it used in the DOM!
syncObject.$bindTo($scope, "data");

Problems occur when I go "Fotogalerie" and click that little (i) icon to toggle description
http://tr.tomasreichmann.cz
Reply all
Reply to author
Forward
0 new messages