I am using angularjs 1.5 and in that trying to copy one object in another variable. To copy the variable, I am using angular.copy() function. The destination variable is not getting all the values which is there in source.
Below is my code
$scope.searchCond = {
group_id:[],
sections:[]
};
for(var i=1;i<5;i++) {
$scope.searchCond.sections[i+"_sec"]=[];
$scope.searchCond.sections[i+"_sec"]["section_id"]=[];
$scope.searchCond.sections[i+"_sec"]["section_id"].push(i);
};
var tmpVar = angular.copy($scope.searchCond);
console.log(tmpVar);
console.log($scope.searchCond);
Output of both the console are given below
OutPut of $scope.searchCond
{group_id: Array(0), sections: Array(0)}
group_id:[]
sections:Array(0)
1_sec:[section_id: Array(1)]
2_sec:[section_id: Array(1)]
3_sec:[section_id: Array(1)]
4_sec:[section_id: Array(1)]
OutPut of tmpVar
{group_id: Array(0), sections: Array(0)}
group_id:[]
sections:Array(0)
length:0
tmpVar is not copying sections(1_sec,2_sec) from the source object $scope.searchCond
Is there any solution for this problem?