Angular 2 error:Supplied parameters do not match any signature of call target
Angular 2 error:Supplied parameters do not match any signature of call target
我正在我的 Angular 2 应用程序中构建一个 RESTful 服务以连接到远程后端。
我的 GET(所有)/POST 方法似乎没问题,我的 PUT 方法似乎没问题,但是我的 GET(单个对象)方法,看起来就像 PUT 方法,抛出以上错误:提供的参数与调用目标的任何签名都不匹配。
这会在编译期间引发错误:
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);
}
这个有效:
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);
}
想法?我做错了什么?
get
不支持 body
参数
return this.http.get(courseUrl, { course }, options)
应该是
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
我正在我的 Angular 2 应用程序中构建一个 RESTful 服务以连接到远程后端。
我的 GET(所有)/POST 方法似乎没问题,我的 PUT 方法似乎没问题,但是我的 GET(单个对象)方法,看起来就像 PUT 方法,抛出以上错误:提供的参数与调用目标的任何签名都不匹配。
这会在编译期间引发错误:
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);
}
这个有效:
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);
}
想法?我做错了什么?
get
不支持 body
参数
return this.http.get(courseUrl, { course }, options)
应该是
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