2016-09-01 31 views
0

我在服務中的功能如下:如何在函數angular2中記錄正在發生的事情?

return this.http.get(this.heroesUrl) 
     .toPromise() 
     .then(response => response.json().data as Hero[]) 
     .catch(this.handleError); 

我的問題是,我想實際註銷什麼「反應」是。當我做這樣的事情時,我得到一個錯誤:

 return this.http.get(this.heroesUrl) 
      .toPromise() 
      .then(response => { 
console.log(response); 
response.json().data as Hero[]; 
}) 
      .catch(this.handleError); 

什麼是正確的方式來看看響應中的內容?

回答

1

好像你忘了return

return this.http.get(this.heroesUrl) 
    .toPromise() 
    .then(response => { 
     console.log(response); 
     return response.json().data as Hero[]; <== here 
    }) 
    .catch(this.handleError); 
+0

謝謝。只是問,你是否會在生產中使用angular2,即使它現在是rc? – Rolando

相關問題