我正在尝试复制所有$ rootScope。来自Angular的$$ childTail for save in variable。我怎么能这样?
我有这段代码:
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;
}
});
但是当我在对象中有循环引用时返回错误:“将循环结构转换为json angular”。
如果添加代码:
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
}
删除我的$ rootScope。$$ childTail对象的项目。
¿任何想法?
谢谢!!!!