【发布时间】:2018-08-22 09:04:21
【问题描述】:
我正在开发一个 Angular 6 项目,在将代码从使用 Http 更改为 HttpClient 时,我收到以下错误:
当我尝试这样做时:
verifyEmail(email: string, verificationCode: string): Observable<HttpResponse<boolean>> {
return this._http.get<boolean>(`${this.serviceUrl}emailVerification?email=${email}&verification_code=${verificationCode}`, { observe: 'response' }).pipe(
map((response: HttpResponse<boolean>) => {
return resp.status === 204;
}),
catchError(this.handleError));
}
我得到了错误
Type Observable<boolean> is not assignable to type Observable<HttpResponse<boolean>>
反过来说:
deleteCollection(collection: Collection): Observable<HttpResponse<boolean>> {
return this._http.delete<boolean>(this.serviceUrl + collection.id, this.requestOptionsResponse).pipe(
map((response: HttpResponse<boolean>) => {
return response.status === 204;
}),
catchError(this.handleError),);
}
报告没有错误,this.requestOptionsResponse 为
private setRequestOptionsResponse() {
let headers = new HttpHeaders({
'Accept' : 'application/json',
'Content-Type': 'application/json'
});
this.requestOptionsResponse = { headers: headers, observe: 'response', withCredentials: true}
}
【问题讨论】:
-
删除后,您的地图将被输入:
(response: HttpResponse<boolean>)