0

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,

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.