检查 .then AngularJS 中返回的数据

Check data being returned in a .then AngularJS

我正在尝试找出最好的方法来检查在我的 .then{}

中返回到我的回复的内容

例如,我可以向 .then{} 添加一个 console.log 以查看返回的内容吗?

以下是我检查此数据的失败尝试:

return myValidationService.getUserDetails(userId)
                        .then(response => response.data.data
                          //This is where I want to add my log
                          console.log("This is my response data: " + response.data.data))
                        .catch(error => pageErrorService.go(pageErrorService.errorDetails.genericError, error));

不过,我收到了 linter 对上述语法的投诉。

检查此数据的标准方法是什么?

在angular1.x中是这样的:

.then(function(response){
  console.log(response.data);
})

问题出在语法中

return myValidationService.getUserDetails(userId)
     .then(response => response.data.data
       //This is where I want to add my log
       console.log("This is my response data: " + response.data.data))
     .catch(error => ....));

您在代码中使用了粗箭头:

 .then(response => response.data.data
      //This is where I want to add my log
       console.log(...)
  )

以上代码同写

.then(function(response){
   return response.data.data
})

上面的代码在被控制台之前返回值

添加花括号将适用于您的情况。你可以写这样的东西来记录值:

 .then(response => {
      console.log(...);
      return response.data.data;
  })