提供的参数与调用目标的任何签名都不匹配 - 角度2

时间:2017-02-24 16:29:45

标签: angular

我正在进行http get请求,但提供的参数与调用目标的任何签名都不匹配。我该如何纠正这个?

 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());

    }

1 个答案:

答案 0 :(得分:2)

如果您使用的是版本2,http.get会返回一个Observable,因此可能是因为您在函数上没有返回类型而导致该问题

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());

}