user2095956
user2095956

Reputation: 433

unbind $scope param from var angular

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

Answers (1)

Kalhan.Toress
Kalhan.Toress

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

Related Questions