Reputation: 474
How can we use two different instances of scope objects
For example :
$scope.seriesdata = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
];
$scope.currentseries = $scope.seriesdata;
Now if I update $scope.currentseries , $scope.series got automatically updated.
For Example :
$scope.currentseriesdata.splice(index,1);
This updates both $scope.currentseriesdata and $scope.seriesdata
Before writing this : I read this
I dont need to work in factory .
I just need to know how to have different instances within controller
Upvotes: 0
Views: 54
Reputation: 2351
It's because you're assigning to currentseries
reference to the array that is already referenced by seriesdata
. This means you have two variables that point to one array.
You want to use slice
$scope.currentseries = $scope.seriesdata.slice();
Upvotes: 1
Reputation: 191829
Just copy the contents before operating on them:
$scope.currentseries = angular.copy($scope.seriesdata);
Upvotes: 3