I'm seeking clarification on the behavior of AngularJS, especially in terms of JavaScript.
In my code, I have a controller that has an Angular factory injected into it.
Here's a snippet from the controller:
$scope.localObjCollection = myObjFactorySvc.getObjCollection();
Suppose that
myObjFactorySvc.getObjCollection()
returns the following object:
[{"id":1,"name":null,"address":null,"email":null},
{"id":2,"name":null,"address":null,"email":null},
{"id":3,"name":null,"address":null,"email":null},
{"id":4,"name":null,"address":null,"email":null}
]
Essentially, I am using the factory to retrieve the collection and storing it in $scope.localObjCollection
. My inquiry is whether $scope.localObjCollection
contains a copy of the data returned by getObjCollection()
, or just a reference.
If later in the controller, I were to perform
$scope.localObjCollection.push(newObj)
, would it also modify the original collection within the Factory? It seems like it should, but I want to grasp the precise functionality.