javascript - How can I beautify JSON programmatically in angular js? -
i know how beautify json programmatically using javascript. way can achieve:
var obj = {"hello":"world", "test":["hello"]} document.body.innerhtml = ""; document.body.appendchild(document.createtextnode(json.stringify(obj, null, 4)));
but tried in angular js. unable achieve this. step :
<div class="btn btn-primary" ng-click="test()">press</div> <textarea json-formatter rows="20" cols="140" ng-model="json"> </textarea> $scope.test=function(){ var json=json.stringify($scope.json, null, "\t"); /*here if $scope.json {"hello":"world", "test":["hello"]} json return "{\"hello\":\"world\", \"test\":[\"hello\"]}" */ }
here if $scope.json
{"hello":"world", "test":["hello"]}
json
return "{\"hello\":\"world\", \"test\":[\"hello\"]}"
.after that, don't how display beautify json same text area. how resolve problem. there other approach please suggest me ?
there built in feature filtering json {{object | json }}
you can use built in filter code
{{dataobject | json}}
will beautify json, give try.
here working example: