2017-09-05 25 views
0

我試圖找出檢查什麼被返回到我的反應,我.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)); 

我收到投訴我對上面的語法棉短絨雖然。

檢查這些數據的標準方法是什麼?

回答

2

在angular1.x它會以這樣的方式

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

謝謝。我認爲我已經把它加入了這個功能,但由於某種原因,我的棉絨抱怨「;」不知道當我嘗試它時我錯過了什麼,但工作。謝謝! – Denoteone

+0

請標記爲答案已解決 –

0

的問題是在這裏的語法

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

與角度無關。這是一個ES6語法 –