javascript - Angular JSON Filter for Array of Objects -
i using $http fetch collection of users. raw response server this...
[{"id":2,"name":"john doe","email":"johndoe@infosnap.com"}] logging data parameter in success callback shows this...
[object, each: function, eachslice: function, all: function, any: function, collect: function…] 0: object $$hashkey: "004" email: "johndoe@infosnap.com" id: 2 name: "john doe" __proto__: object length: 1 __proto__: array[0] good enough. looks $http de-serialized raw json javascript object.
next, assign data $scope variable, inside success callback, in order perform debugging in browser...
$scope.debug = data; now, in view, want display pretty json in order debug.
<pre>{{debug | json}}</pre> and this...
"[{\"id\": 2, \"name\": \"john doe\", \"email\": \"johndoe@infosnap.com\", \"$$hashkey\": \"004\"}]" i trying this...
[ { "id": 2, "name": "john doe", "email": "johndoe@infosnap.com", "$$hashkey": "004" } ] i tried stringify javascript array in controller...
$scope.debug = json.stringify(data, true); and not use filter...
<pre>{{debug}}</pre> but same results, except $$hashkey has been removed...
"[{\"id\": 2, \"name\": \"john doe\", \"email\": \"johndoe@infosnap.com\"}]" if assign first item in array $scope, , use json filter, works fine...
$scope.debug = data[0]; in view...
<pre>{{debug | json}}</pre> results in...
{ "id": 2, "name": "john doe", "email": "johndoe@infosnap.com" } i know there other ways want. trying understand going on.
thanks!
you should parse json instead of stringify.
try this:
$scope.debug = json.parse(data)
Comments
Post a Comment