angular.copy()
by Paco86
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.1/angular.min.js"></script>
Creates a deep copy of source, which should be an object or an array.
I am not sure how this is different from angular.merge() which also creates a deep copy?
JavaScript
var src = {
likes: {
fruit: [
'apples', 'bananas', 'grapefruit']
}
};
var dest = angular.copy(src);
dest.likes.fruit.push('orange');
// no change in the src object
console.log('src', src.likes.fruit);
// destination object has been changed (of course)
console.log('dest', dest.likes.fruit);