これは、私のコードが新しい4.3 HttpClient(以下を参照)のようになりました。私のメソッドの戻り値の型に注目してください。
getProducts(): Observable<IProduct[]> {
return this._http.get<IProduct[]>(this._productUrl)
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
private handleError(err: HttpErrorResponse) {
// in a real world app, we may send the server to some remote logging infrastructure
// instead of just logging it to the console
let errorMessage = '';
if (err.error instanceof Error) {
// A client-side or network error occurred. Handle it accordingly.
errorMessage = `An error occurred: ${err.error.message}`;
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
errorMessage = `Server returned code: ${err.status}, error message is: ${err.message}`;
}
console.error(errorMessage);
return Observable.throw(errorMessage);
}
どのようなツールがこのメッセージを提供していますか?それはそのようなオブジェクトをすべて列挙していますか?前の行では正しいタイプを表示しているようです。 – DeborahK
ブラウザ内で、VSCodeデバッガ内にある私のスクリーンショットから。私は、成功後にValidateEmailResponseのインスタンス用の単純なconsole.logを追加し、ログをスキップします。画像としての前の行はコンソールログValidateEmailResponse success - > objectです。 –