In the beginning of my Angular controller, I use Promises to download JSON data and then store it in variables:
app.controller('mainController', ['$scope', '$http', '$q', function($scope, $http, $q) {
var req1 = $http({method: 'GET', url: 'link to JSON 1', cache: 'true'});
var req2 = $http({method: 'GET', url: 'link to JSON 2', cache: 'true'});
$q.all([req1, req2]).then(function(response){
var res1 = response[0].data;
var res2 = response[1].data;
$scope.data1 = res1; // Manipulated JSON
$scope.data1Ref = res1; // Reference JSON
$scope.data2 = res2;
$scope.data2Ref = res2;
init(); // Process the data
});
}]);
However, after init()
is executed, both $scope.data1
and $scope.data1Ref
seem to be bound together, leading to modifications in one affecting the other.
I am wondering why this happens and how can I keep a separate stored version of the original downloaded JSON for reference?