I have two objects:
$scope.copy;
$scope.myObject;
Now when ever user changes anything it is reflected in myObject
variable.
Later on I would like to compare two scope variables for equality like below:
angular.equals($scope.copy,$scope.myObject);
But the problem here is whenever user updates anything Angular.JS add hashkey and so because of that my above comparison is failing.
So as per my research, I found that I need to add track by everywhere to remove $hashkey and adding track by boost up performance as per following references:
https://www.timcosta.io/angular-js-object-comparisons/
What is the $$hashKey added to my JSON.stringify result
But I have some confusion and I hope if someone could clear it:
Does Angular add a hashkey in JSON even if I update any textbox value, or it add only in case of ngrepeat?
With ngrepeat can I blindly add track by $index or I need to add unique field like track by id but in some case I don't know? Would value will be unique or duplicate so can I add everywhere track by $index?
If I blindly add track by $index instead of track by id (i.e name of field) then will I have same performance benefit without any problem as we have in track by id?