Reputation: 3580
I'm building a RESTful service in my Angular 2 app to connect to a remote back end.
My GET (all) /POST methods seem to be fine, and my PUT method seems to be fine, but my GET (single object) method, which looks just like the PUT one, throws the above error: Supplied parameters do not match any signature of call target.
This throws an error during compilation:
getCourse (course: Course): Observable<Course> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let courseUrl = this.BaseUrl + '/' + course.id;
return this.http.get(courseUrl, { course }, options)
.map(this.extractData)
.catch(this.handleError);
}
This works:
put(course: Course): Observable<Course> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let courseUrl = this.BaseUrl + '/' + course.id;
return this.http.put(courseUrl, { course }, options)
.map(this.extractData)
.catch(this.handleError);
}
Thoughts? What am I doing wrong?
Upvotes: 1
Views: 2367
Reputation: 657308
get
doesn't support a body
parameter
return this.http.get(courseUrl, { course }, options)
should be
return this.http.get(courseUrl, options)
https://angular.io/docs/ts/latest/api/http/index/Http-class.html#!#get-anchor
get(url: string, options?: RequestOptionsArgs) : Observable
https://angular.io/docs/ts/latest/api/http/index/Http-class.html#!#put-anchor
put(url: string, body: any, options?: RequestOptionsArgs) : Observable
Upvotes: 2