How to convert string to object in Angularjs [duplicate] How to convert string to object in Angularjs [duplicate] json json

How to convert string to object in Angularjs [duplicate]


You can do it with angular.fromJson()

in your sample, it would have been $scope.tmp = angular.fromJson($scope.text);

The difference between JSON.Parse() and angular.fromJson, is that angular will check to make sure a string is provided. If it is already an object, it will return the same object.