Reputation: 3589
I've spent a good hour trying to debug this but I have absolutely no idea why this would be wrong.
I've been trying to display a row of images onto a page using Angular based upon data retrieved from a json file. However, Angular keeps giving me this error:
SyntaxError: Unexpected token }
at Object.parse (native)
at fromJson (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:1076:14)
at defaultHttpResponseTransform (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:8651:16)
at http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:8736:12
at forEach (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:327:20)
at transformData (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:8735:3)
at transformResponse (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:9465:23)
at processQueue (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:13293:27)
at http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:13309:27
at Scope.$get.Scope.$eval (http://localhost:3000/assets/angular.self-5bf4e8cd0241c34665eca1c336b104c0716c32c68edd291d6ae5b0e0935d29ec.js?body=1:14548:28)
Here's my code
HTML:
<div id="officersPage" class="row" ng-app="officers" ng-controller="officerCtrl">
<div id="officerModals" class="col-md-4" ng-repeat="officersOne in officersGroup">
<div class="officerPics" ng-repeat="officer in officersOne">
<%= image_tag('logo.png', :id=>"{{officer.id}}", size: '140x140', :class=>"img-responsive, img-thumbnail") %>
</div>
</div>
<div id="moreDetails" class="col-md-4">
</div>
</div>
Angular code:
# Contains the Angular code for the officer page -> will generate all the pictures and modals based on info through JSON file
app = angular.module('officers', [])
app.controller 'officerCtrl', [
'$scope'
'$http'
($scope, $http) ->
$http.get('./officers.json').success (data) ->
console.log(data)
$scope.officersGroup = data
console.log($scope.officersGroup)
return
]
Any help would be awesome!
Edit: Here's what a sample of the JSON file looks like:
{
"officers": [
{
"name": "Matt Zhang",
"role": "Webmaster",
"class": "2018",
"id" : "matt"
}
]
}
Upvotes: 0
Views: 667
Reputation: 812
Just a guess, when you assign:
$scope.officersGroup = data
Shouldn't be?
$scope.officersGroup = data.officers
That is for the first iteration in your code. Then in the second iteration, are you using ng-repeat for iterate over the properties of an object? If it so, I do not think is the best way to do it.
<div class="officerPics" ng-repeat="officer in officersOne">
Cheers
Upvotes: 1