why array become blank after splitting into multiple small array?

36 views Asked by At

hello I have one a array $scope.name .I am spliting the array into small arrays .But after spliting the array .it become blank why ? actually I assigned the given array into temp variable and splite the temp variable .Again my $scope.name become blank why ?

here is my plunker http://plnkr.co/edit/iUscrw0xclHSnsIWMMTM

    console.log("before");
    console.log($scope.name);
    var test=$scope.name;
     console.log("after");
      console.log($scope.name);
    console.log("test");
    console.log(test);
    var arrays = [], size = 3;

while (test.length > 0)
    arrays.push(test.splice(0, size));

console.log(arrays);
console.log("name");
    console.log($scope.name);
1

There are 1 answers

2
Pankaj Parkar On BEST ANSWER

You are directly assigning object to other object, so that will cause change in any of the object will update other object value. Use angular.copy instead of assigning object directly, that will create a new clone copy of that object will returned.

 var test=angular.copy($scope.name);

Forked Plunkr