[英]Angular SyntaxError: Unexpected token }
我花了好一個小時來調試它,但是我絕對不知道為什么這是錯誤的。
我一直在嘗試根據從json文件檢索的數據,使用Angular在頁面上顯示一行圖像。 但是,Angular一直給我這個錯誤:
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)
這是我的代碼
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>
角度代碼:
# 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
]
任何幫助都是極好的!
編輯:這是JSON文件的示例:
{
"officers": [
{
"name": "Matt Zhang",
"role": "Webmaster",
"class": "2018",
"id" : "matt"
}
]
}
只是一個猜測,當您分配時:
$scope.officersGroup = data
不應該嗎
$scope.officersGroup = data.officers
那是代碼中的第一次迭代。 然后在第二次迭代中,您是否使用ng-repeat迭代對象的屬性? 如果是這樣,我認為這不是最好的方法。
<div class="officerPics" ng-repeat="officer in officersOne">
干杯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.