2

How can I ng-repeat this kind of json data? I want to echo game and stats separataly.

{
"game": [
 {
 "home": "Home Team",
 "away": "Away Team",
 "date": "2015-01-13",
 "result": "2-0"
 }
 ],
 "stats": [
 {
 "event": "Goal",
 "time": 27,
 "player": "Player One"
 },
 {
 "event": "Yellow Card",
 "time": 52,
 "player": "Player Two",
 }
 ]
 }

Thank you in advance!

1 Answer 1

2

You just have to feed ng-repeat the data inside each object. Let's say that the JSON you posted is stored in $scope.data. To get show the game information, just give ng-repeat the game array like so:

<div ng-repeat="g in data.game">
Home: {{g.home}}<br>
Away: {{g.away}}<br>
Date: {{g.date}}<br>
Result: {{g.result}}
</div>

Do the same thing with stats and you display the information from each array.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I already tried it like this but it didn't work. But now, after 3 hours of playing around I realised that the problem is that those brackets are conflicting with laravel blade.. I feel so stupid now :D But anyway, this is the right answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.