観測

2017-05-10 7 views
2

と角度2 HTTPサービスにおけるHTTP GETリクエストを作成するにはどのように私はちょうど今、私は「観測を学ぶんです!うわ! 観測

ちょうど緩く、このチュートリアルの次の角4と、単純なGETリクエストをしようと約束をマスタリング終了:私は rxjs/Observableから Observableをインポートしようとしたとき https://scotch.io/tutorials/angular-2-http-requests-with-observables

は当初、私はコンパイルエラーは、基本的にちょうどrxjsコンパイルエラーを解決するためにマップがObservable<Response>の機能はなかったと言ってますが、輸入を変えました。しかし、今、私は同じ得ます。実行時のエラー...

以下のレスポンスをどのように処理しているのですか?

import { Injectable } from '@angular/core'; 
import { apiConfig } from '../../environments/environment'; 
import { Http, Response, Headers, RequestOptions } from '@angular/http'; 
import { APIRequest, APIResponse} from './api-objects'; 
import { Observable } from 'rxjs'; 

/** 
* The BaseAPIService can be extended to provide base functionality for communicating to the API endpoint. 
*/ 
@Injectable() 
export class BaseAPIService { 

    private apiBase = apiConfig.base; 

    constructor(protected http: Http) { } 

    /** 
    * Sends an API request to the endpoint 
    */ 
    sendRequest(request: APIRequest): Observable<APIResponse> { 
    const options = new RequestOptions({ }); 
    const fullUrl = `apiBase${request.url}`; 
    request.body = request.body || {}; 
    return this.http.get(fullUrl).map((response: Response) => new APIResponse(response)); 
    } 
} 

**エラーの詳細**

this.http.get(...).map is not a function 
    at CoreAPIService.webpackJsonp.356.BaseAPIService.sendRequest (base-api.service.ts:25) 
+3

あなたは、次のインポートする必要があります: 'インポート 'rxjs /追加/オペレータ/マップを';' – Haseoh

答えて

0

また、あなたが使用する予定のRxJS演算子をインポートする必要があります。これはモジュールレベルで行うことができます。

例:

import 'rxjs/add/operator/map'; 
import 'rxjs/add/operator/catch'; 
import 'rxjs/add/operator/switchMap'; 
+0

大きな感謝。できます。 –