What is $$ hasKey in array items?

0

I noticed that for some reason, a property called $$ hasKey has been added to the items in my array. Each item has this property with different values.

Example:

[0: {$$hasKey: 'Object1', 
    uf: 'ES'},
 1: {$$hasKey: 'Object2',
    uf: 'SP'}
]

In this example is an acronym list of Brazilian states, the object I load from the server does not have the property $$hasKey , and my array comes without this property up to my controller .

When debugging I was unable to find the time when this property is added to the items in my array .

I want to understand:

  • What's this
  • What is it for?
  • If you have remove
asked by anonymous 04.05.2018 / 15:39

1 answer

1
  

What's this?

The $$HashKey property is created internally by AngularJS (more explicitly by the internal function $id() ) when the library needs to uniquely identify the members of a collection - such as the use of ng-repeat .

  

What's the use?

In order for AngularJS to be able to map members of collections individually.

When you use ng-repeat='item in items' without specifying a track by internally ng-repeat will apply track by $id(item) . This function will calculate the hash on objects, or return the value directly in primitives.

  

Can you remove it?

Yes. The native function angular.toJson() removes all internal properties - but remember that it returns a string , and you need to deserialize it back to an object via JSON.parse() :

var objetoPuro = JSON.parse(angular.toJson(objetoComHashKey));
    
04.05.2018 / 17:00