当我尝试从API请求处理回调函数时,Sentry报告了一个错误,成功函数在数据中返回未定义。
这是我的代码
---控制器---
angular.module('candidateLanguagesController', [])
.controller('candidateLanguagesController',[ '$scope', '$http', 'CandidateLanguages', 'Helper',function($scope, $http, CandidateLanguages, Helper) {
$scope.init = function(uuid)
{
$scope.uuid = uuid;
$scope.candidateLanguages = {};
CandidateLanguages.show($scope.uuid)
.success(function(data) {
$scope.candidateLanguages = data.data;
if( Helper.isEmpty($scope.candidateLanguages) ){
$scope.candidateLanguages.push({id:'newLanguage', language_id:'', languagelevel_id:''});
}
}).error(function(data) {
console.log(data);
});
}; }]);
---服务---
angular.module('candidateLanguagesService', [])
.factory('CandidateLanguages', ['$http','$location',function($http,$location) {
var host = $location.protocol();
var domain = $location.host();
var url = host+'://'+domain;
return {
show : function(uuid) {
return $http.get(url+'/api/v1/candidates/'+uuid+'/languages');
}
}
}]);
--- App ---
var SignupSPA = angular.module('SignupSPA', ['candidateLanguagesController', 'candidateLanguagesService','helperService']);
- JSON响应 -
{"data":[{"id":51571,"language_id":6,"languagelevel_id":4,"name":"English","percent":"75%","level_description":"Puedo conversar de manera fluida y sin errores. (TOEFL CBT > 240 o PBT > 580)"}]}