AngularJS: is $$hashkey a reliable key

后端 未结 2 1843
甜味超标
甜味超标 2021-01-22 01:47

Question

I\'m interested in the properties of $$hashkey on angular arrays/objects.

  1. Would each generated hashkey be the same each time you
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-22 02:29

    $$hashkeys will only be computed for functions and objects so if you wish to track anything that isn't one of those types then you have that limitation.

    $$Hashkeys look like ... (function||object): N ...

    Where N is just an incremental value being adjusted + 1 for each $$HashKey computed. So, in many cases this could be the same value across page loads. But loading data that is asynch, will cause differences when multiple data sources are being queried as part of page initialization and order of return cannot be guranteed. In cases like that you would have to marshall all your asynch data and then assign that data to your scope in a specific order to ensure consistent $$hashkeys.

    Moving items around in an array that is linked to our DOM (via ng-repeat) will not change that items $$hashkey. Deleting it and re-adding it will.

    I would not use $$Hashkey for my own housekeeping as it is intended to be internal to AngularJS.

提交回复
热议问题