0

Just started with angular and I am debugging my angular app and would like to save a large json object. Is it possible to save this in chrome? Or how to save this with angular? Extra info: I want to save the contents of $rootScope to a json file.

bier hier
  • 20,970
  • 42
  • 97
  • 166
  • 1
    Define exactly what you mean by *"to file"*. You could store it in [local storage](https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API) but if you actually want to write the contents to a file, you'll *probably* need a server-side component. – Phil Nov 24 '15 at 01:13
  • Possible duplicate of [Is it possible to write data to file using only JavaScript?](http://stackoverflow.com/questions/21012580/is-it-possible-to-write-data-to-file-using-only-javascript) – Phil Nov 24 '15 at 01:14
  • your question is nebulous, please be more specific. – Darryl Nov 24 '15 at 01:20
  • is that specific enough? – bier hier Nov 24 '15 at 02:07

2 Answers2

0

Not sure from your question where you want to save the file so I'll assume server side you could post the json to a rest service using $post (a get request will probably be too long) on the server that writes the file with the posted contents.

  • Save on my local machine, I just want to use the contents as a mockfile. – bier hier Nov 24 '15 at 04:00
  • Why not just do a console.log(myjson) and copy an paste in to a file. Or using angular binding throw a temporary {{myjson | json}} binding on the page. Adding the pipe Jason on the page will writ out the object in json notation. – Josh Pendergrass Nov 24 '15 at 11:53
  • it just says : $SCOPE when I use {{rootScope|json}} – bier hier Dec 03 '15 at 23:51
0

You should use the browser tools from your favorite browser. in your code write this code:

// .. 
var json = JSON.stringify($rootScope);
console.log(json);

You will be able to copy the content from the console and you can save it into a new text file.

Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73