Hello I have a questions on ng-repeat on Angularand function for change value.
I have this ng-repeat
that cycling a ObjectArray and have a button for reset value.
<div ng-repeat="element in data.elements">
<button ng-click="reset(element)" >reset</button>
</div>
Where data.elements
is array of objects example:
[{id:1, name:"element1"},{id:2, name : "element2"}];
In my Controller
I set function Reset in $scope
that should do a copy of object passed to an default object:
$scope.reset = function(el){
$scope.defaultObject = {id:500, name:"default"};
el = angular.copy($scope.defaultObject);
}
But doesn't work, but if I do:
$scope.reset = function(el){
$scope.defaultObject = {id:500, name:"default"};
el.name = $scope.defaultObject.name;
}
It work. So I would like that when I do (in this example):
el = angular.copy($scope.defaultObject);
have the object el
equals to object $scope.defaultObject
my question is, Can i copy entire object without cycling all properties?