Angularjs 如何在访问服务时避免未定义的错误?
我在单独的文件中创建了服务。但我在控制台中得到错误,说Angularjs 如何在访问服务时避免未定义的错误?,angularjs,Angularjs,我在单独的文件中创建了服务。但我在控制台中得到错误,说无法读取未定义的属性 这就是失败的代码 github.getUser($scope.username).then(onUserComplete, onError); 这是我的链接,指向您必须从您的服务方法中实际返回$http.get()服务返回的承诺,而不仅仅是调用它: var getUser = function(username){ return $http.get("https://api.github.com/users
无法读取未定义的属性
这就是失败的代码
github.getUser($scope.username).then(onUserComplete, onError);
这是我的链接,指向您必须从您的服务方法中实际返回$http.get()
服务返回的承诺,而不仅仅是调用它:
var getUser = function(username){
return $http.get("https://api.github.com/users/" + username)
.then(function(response){
debugger;
return response.data;
});
};