Reputation: 33
Im new to AngularJS. Now I have a json object from my spring controller, how do i use/print in my jsp?
I tried something like this. the console shows the json perfectely, and with angular it does not...
<div data-ng-init="stats=${stats}">
<li data-ng-repeat="stat in stats">{{stat.name}}</li>
</div>
<script>
console.log(${stats});
</script>
Json:
{ "Types": [{"name": "study", "value":0},{"name": "health", "value":0},{"name": "culture", "value":0},{"name": "nightlife", "value":0},{"name": "other", "value":0},{"name": "friendship", "value":0}] })
Upvotes: 3
Views: 96
Reputation: 193311
Because JSON string must be properly quoted if placed into HTML attribure value, you either escape "
characters in JSON or probably better use '
quotes for ngInit
:
<div data-ng-init='stats=${stats}'>
<li data-ng-repeat="stat in stats.Types">{{stat.name}}</li>
</div>
Demo: http://plnkr.co/edit/XLIE9VCSn9gL3oO6ULol?p=info
Upvotes: 2
Reputation: 54811
You need to reference the array property of stats
.
<li data-ng-repeat="stat in stats.Types">{{stat.name}}</li>
Upvotes: 2