1

Hello how can I pass $scope data to JSON when I initialise it?

e.g I have scope users:

$scope.users = [
  { name: "Camila Gilson" },
  { name: "Chloe Creighton" },
  { name: "Zoey White" }
];

I want to store users's info in json, is it possible?

Thanks?

2
  • 1
    JSON.stringify($scope.users) Commented Jun 6, 2014 at 14:52
  • What do you mean by store the user's info? Store it where? Commented Jun 6, 2014 at 14:53

1 Answer 1

3

Yes, this is what toJson and fromJson are for

angular.toJson($scope.users);

Will result in a string with JSON format and

angular.fromJson(yourJsonString);

Will convert it back.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.