提供的参数与呼叫目标的任何签名不匹配 - angular 2
问题描述:
我正在发出http get请求,但提供的参数与呼叫目标的任何签名都不匹配。我如何纠正这一点?提供的参数与呼叫目标的任何签名不匹配 - angular 2
getFood(id){
let headers = new Headers({ 'Authorization': 'Bearer ' + this.auth.token });
let options = new RequestOptions({ headers: headers });
return this.http.get('http://localhost:8000/routes/food_serve/v1/foodlist/'+id+'/food', options)
.map((response:Response) => response.json());
}
答
,如果您使用的版本2 http.get返回可观察到的,所以也许这是个问题,你对功能没有返回类型
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Rx';
getFood(id): Observable<Response> {
let headers = new Headers({ 'Authorization': 'Bearer ' + this.auth.token });
let options = new RequestOptions({ headers: headers });
return this.http.get('http://localhost:8000/routes/food_serve/v1/foodlist/'+id+'/food', options)
.map((response:Response) => response.json());
}
你有这些进口'进口{HTTP,RequestOptions ,Headers,Response} from'@ angular/http';导入'rxjs/add/operator/map';'? – yurzui
@yurzui是的,我已经将它们导入 – XamarinDevil
究竟哪一条线会抛出错误? – yurzui