Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何在访问服务时避免未定义的错误?_Angularjs - Fatal编程技术网

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;
        });
    };