2017-03-08 83 views
1

的界面我有一個接口來調用用戶,我試圖來初始化對象,如下面:使用可觀察到初始化角2

constructor(private _http: Http) { } 

    getUsers(): Observable<User[]> { 
     return this._http.get(this._url) 
      .map((response: Response) => response.json()) 

      .do(data => console.log("User data" + JSON.stringify(data))) 
      .catch(this.handleError); 
    } 

    private handleError(error: Response) { 
     console.log(error); 
     return Observable.throw(error.json().error || 'Internal Server error'); 
    } 

但是我收到以下錯誤。

The type argument for type parameter 'T' cannot be inferred from the 
usage. Consider specifying the type arguments explicitly. Type 
argument candidate 'Response' is not a valid type argument because it 
is not a supertype of candidate 'Response'. Types of property 'type' 
are incompatible. Type 'string' is not assignable to type 'ResponseType' 

URL是JSON文件的文件路徑。我試圖用這種方式進行設置,這樣我可以更容易地轉換到真正的HTTP調用,但現在我想從JSON文件中使用模擬數據。

+0

有你的輸入:從'進口{響應} '@角/ HTTP';' ? – micronyks

+0

那就是它 – Drew1208

回答