Reputation: 396
I have a question regarding getting a data value from a JSON array that has no key value in Angular. I've seen plenty of examples getting the value out with a key, but I have not been able to figure this piece out.
The JSON that is returned from the API is quite complicated and looks like...
[{"":796}]
Its then assigned in the controller using this..
$http({
method: 'GET',
url: 'api/getnumassets'
}).success(function(data) {
$scope.numAssets = data; // response data
});
Now when I use the snippet below to get the number out, I get the following value: {"":796} when I want it to display 796.
<div class="number">
{{numAssets}}
</div>
<div class="desc">
{{'viewport.totalAssets' | translate}}
</div>
I've tried a number of different accessors on the numAssets expression but I have yet to have any luck. Any help would be much appreciated!
Upvotes: 1
Views: 719
Reputation: 191
If object is obj = {"":796}
you can access its property this way: obj['']
.
Upvotes: 2