0

I'm trying copy all $rootScope.$$childTail of Angular for save in variable. How can I this?

I have this code:

        var newObject = JSON.stringify($rootScope.$$childTail, function(key, value) {
                if((key.indexOf("$") === -1 || key === '$$childTail') && typeof value !== 'function'){
                        // Store value in our collection
                        cache.push(value);
                    }
                    return value;
                }
            });

But when I have circular references in the object returned the error: "Converting circular structure to json angular".

If add the code:

if (typeof value === 'object' && value !== null) {
     if (cache.indexOf(value) !== -1) {
         // Circular reference found, discard key
         return;
}

This remove items of my $rootScope.$$childTail object.

¿Any idea?

THANK YOU!!!!

  • 1
    Possible duplicate of [Deep copying objects in angular?](http://stackoverflow.com/questions/14360401/deep-copying-objects-in-angular) – Mistalis Jan 27 '17 at 10:52
  • angular.copy not allow copy of Window or Scope: Can't copy! Making copies of Window or Scope instances is not supported. – dolo2012res Jan 27 '17 at 11:06

0 Answers0