Reputation: 433
I have $scope.attributesList = [{name:"",val:""}....]
in some cases I need to copy my list and unbind it from my destination param.
var param = $scope.attributesList;
the problem is each time $scope.attributesList changed my param also changed, I need my param to be static after I copied my $scope.attributesList and not to changed. What is the way to unbind it?
Thanks,
Upvotes: 0
Views: 33
Reputation: 21901
You need a deep copy of the object, to do that use angular.copy()
var param = angular.copy($scope.attributesList);
if we using like var param = $scope.attributesList;
then both param
and $scope.attributesList
are pointed to same object because $scope.attributesList
is a reference type
If we use primitive type like 1,2
as,
$scope.attributesList = 1;
var param = $scope.attributesList;
then param
and $scope.attributesList
are independent.
Upvotes: 1