【发布时间】:2019-11-23 00:59:18
【问题描述】:
为所有调用创建了一个通用的 httpServie。
export class HttpApiService {
constructor( private httpClient: HttpClient) {}
public getData<T>(url: string, headers?: HttpHeaders): Observable<T> | Observable<any> {
this.customReqOptions = this.getHeaders(headers);
return this.httpClient.get(`${this.endPoint}${url}`, { headers: this.customReqOptions});
}
}
从用户服务调用它
export class UserService {
constructor(private httpApi: HttpApiService) {
}
public getUsers(): Observable<any>{
return this.httpApi.getData('users')
.pipe(
tap((res) => {console.log('res,',res)}),
publishReplay(1),
refCount()
);
}
}
管道 () 一个给出错误 TS2554: Expected 0 arguments, but got 3.
为参考创建了一个代码:https://stackblitz.com/edit/anglearn
我错过了什么? 虽然使用最新版本@angular: v8, rxjs: 6.4 using ngcli.
【问题讨论】: