Deep copying objects in angular?

后端 未结 3 439
野性不改
野性不改 2020-12-05 01:39

I wonder if there is away to avoid copying references to objects when you need to create a simple object which has an array of embedded objects.The situation is as follow: I

3条回答
  •  温柔的废话
    2020-12-05 02:10

    I personally use this:

        function copyObjToObj(source, destination) {
            if(!angular.equals(source,destination)){
                if (!!destination) 
                    angular.copy(source, destination);
                else 
                    destination = angular.copy(source);
            }
            return destination;
        }
    var destination = copyObjToObj(sourceObj, destination);
    

提交回复
热议问题