We have tried angular.copy and angular.extend. Both of these, though, copy property values. How do we copy one object's properties, without their values, to another object?
Here is a fiddle with our attempts based on how-to-quickly-clear-a-javascript-object.
angular.module('App', []);
function Ctrl($scope) {
function copyNotValues(obj) {
var newObj = angular.copy(obj);
for (prop in newObj) {
if(newObj.hasOwnProperty(prop))
{
newObj[prop] = null;
}
};
return newObj;
}
$scope.master = {
foo: 'original foo',
bar: 'original bar'
};
$scope.copy = angular.copy($scope.master);
$scope.extend = angular.extend($scope.master);
$scope.copyNotValues = copyNotValues($scope.master);
}