How to convert string to object in Angularjs
This question already has an answer here:
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.