【发布时间】:2014-07-18 09:18:14
【问题描述】:
我刚开始学习 Javascript 和 AngularJS,并且拥有不错的 Java 和 C++ 背景。
今天我浪费了一整天的时间来调试一个小错误,该错误归结为 JSON 文件中缺少逗号:"name": "Melbourne",
"snippet": "Melbourne"
"location":{"lat": "37.8136S", "long": "144.9631E"}
现在我想知道: Javascript/AngularJS 的调试方式是什么? - 对于这种特定情况以及一般情况。花 8 小时更改代码中的每一行都不是解决方案。 在 C++/Java 中,我会查看堆栈跟踪,因此我检查了 chrome 控制台输出并发现:
SyntaxError: Unexpected string
at Object.parse (native)
at fromJson (http://localhost:8000/app/bower_components/angular/angular.js:1078:14)
at $HttpProvider.defaults.defaults.transformResponse (http://localhost:8000/app/bower_components/angular/angular.js:7317:18)
at http://localhost:8000/app/bower_components/angular/angular.js:7292:12
at Array.forEach (native)
at forEach (http://localhost:8000/app/bower_components/angular/angular.js:323:11)
at transformData (http://localhost:8000/app/bower_components/angular/angular.js:7291:3)
at transformResponse (http://localhost:8000/app/bower_components/angular/angular.js:7963:17)
at wrappedCallback (http://localhost:8000/app/bower_components/angular/angular.js:11319:81)
at http://localhost:8000/app/bower_components/angular/angular.js:11405:26 angular.js:9778
这对我有什么帮助?我什至没有看到任何远程告诉我检查我的 JSON 或我的代码的东西——只有库代码。我的代码中有问题的行是
//citycontroller.js
$scope.cities= City.query();
//cityservice.js
cityServices.factory('City', ['$resource',
function($resource){
return $resource('cities/:cityId.json', {}, {
query: {method:'GET', params:{cityId:'cities'}, isArray:true}
});
}]);
为什么这两行都没有堆栈跟踪?
【问题讨论】:
标签: javascript json angularjs javascript-debugger