Angular 如何进行一般HTTPClient请求调用?

Angular 如何进行一般HTTPClient请求调用?,angular,typescript2.0,angular5,Angular,Typescript2.0,Angular5,在Angular 5中,我可以使用generic like进行http调用 http.get<Employee>(....) ... 我不完全了解typescript,而且它似乎也不是正确的实现方式 任何都是你的选择: @Injectable() 导出类数据服务{ 构造函数(私有http:HttpClient){} 私人火灾(选项:CustomRequestOptions){ 返回此.http.request(options.request); } } 您的代码应该可以正常工作。你

在Angular 5中,我可以使用generic like进行
http
调用

http.get<Employee>(....) ...

我不完全了解typescript,而且它似乎也不是正确的实现方式

任何
都是你的选择:

@Injectable()
导出类数据服务{
构造函数(私有http:HttpClient){}
私人火灾(选项:CustomRequestOptions){
返回此.http.request(options.request);
}
}

您的代码应该可以正常工作。你面临的问题是什么。如果我调用
this.dataService.fire(options)
,并对其进行调试,我会在chrome开发者工具中得到
T未定义的引用错误。2.我想知道在非泛型类中有泛型方法是否合适
@Injectable()
export class DataService {

    constructor(private http: HttpClient) {} 

    private fire<T>(options: CustomRequestOptions) {
       return this.http.request<T>(options.request);
    }
}