我创建了一个导入JSON并使用它来填充HTML模板的服务的服务。在成功使用不同的应用之前,我已经完成了这项工作。这一次,我收到了错误:
SyntaxError: Unexpected token /
at Object.parse (native)
我几乎肯定问题是不我的JSON,因为我使用的测试JSON已经在我的另一个应用程序中工作,我得到了同样的错误。
我的相关代码:
app.js:
var app = angular.module('ClimbLog', []).config(function($sceProvider) {
// Completely disable SCE
$sceProvider.enabled(false);
});
getClimblogs.js:
app.factory('getClimblogs', ['$http', function ($http) {
return $http.get('http://localhost:8000/exampleJSON.json')
.success(function (data) {
return data;
})
.error(function (err) {
return err;
});
}]);
控制器:
app.controller('MainController',['$scope', 'getClimblogs', function ($scope, getClimblogs){
getClimblogs.success(function (data) {
$scope.climbLogs = data.climbs;
});
}]);
JSON:
{"climbs":[{
"climbID":"xxxxxx",
"date":"Aug. 10, 2015",
"location":"Portland,ME",
"routeName":"Trendsetter",
"type":"Traditional",
"grade":"5.10b",
"partner":"Sarah Smokeshow",
"challengeLevel":8,
"time":6.05,
"notes":"Finally got a chance to send this guy!",
"photo": "https://photoUrl"
},
{
"climbID":"yyyyyy",
"date":"Aug. 10, 2015",
"location":"Brunswick,ME",
"routeName":"Poopmobile",
"type":"Boulder",
"grade":"V10",
"partner":"Sarah Smokeshow",
"challengeLevel":10,
"time":4.05,
"notes":"I'm beat..",
"photo": "https://photoUrl"
}
]}
答案 0 :(得分:0)
一旦我摆脱了它,它就有用了。