Abhishek Kumar Pandey
Abhishek Kumar Pandey

Reputation: 449

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.

Upvotes: 0

Views: 2305

Answers (1)

Thierry
Thierry

Reputation: 5233

You are adding the comment in... the comment!

comment.push(comment);

This creates a circular reference. Maybe you want to do: comments.push(comment) ?

Upvotes: 1

Related Questions