简体   繁体   English

TypeError将循环结构转换为json

[英]TypeError converting circular structure to json

 var app = angular.module('app',['ngStorage']); app.controller('myController', ['$scope','$localStorage', function($scope, $localStorage){ var comment = [ { name : '', rating : '' } ] $scope.saveData = function (review) { comment.push(comment); localStorage.setItem("review", JSON.stringify(comment)); console.log("dkfjhdjhgjh",review); }; }]) 

When I am Inserting through Input Box I am getting TypeError. 通过输入框插入时出现TypeError。

You are adding the comment in... the comment! 您正在...中添加评论!

comment.push(comment);

This creates a circular reference. 这将创建一个循环引用。 Maybe you want to do: comments.push(comment) ? 也许你想做: comments.push(comment)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM