【发布时间】:2017-05-11 21:14:32
【问题描述】:
我正在尝试编写一个用于从我的外部数据库中删除的服务,但我一直看到此错误:
类型参数“T”的类型参数不能从 用法。考虑明确指定类型参数。类型 参数候选“响应”不是有效的类型参数,因为它 不是候选“响应”的超类型。属性“类型”的类型 不兼容。类型“字符串”不可分配给类型 '响应类型'。
^ 并且此错误突出显示该行:
return this.http.delete(`${this.base_url}/${id}`)
这里是服务:
import { Injectable } from '@angular/core';
import { CheckIn } from './check-in';
import { Headers, RequestOptions, Http } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
@Injectable()
export class CheckInService {
private base_url = "http://localhost:3000/";
constructor (private http: Http) {}
delete(id:string): Observable<CheckIn[]> {
return this.http.delete(`${this.base_url}/${id}`)
.map((res:Response) => res.json()) .json() on the response to return data
.catch((error:any) => Observable.throw(error.json().error || 'Server error'));
}
}
我做错了什么?
【问题讨论】: