2017-03-08 85 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

回答