您好我想在Http角对象的重写请求方法中执行http.get(...)。
@Injectable()
export class CustomHttp extends Http {
constructor(backend: XHRBackend, options: RequestOptions, ) {
super(backend, options);
}
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
//some logics
if(//some conditions)
super.get('url');
return super.request(url, options).catch(this.catchError(this));
}
}
当前行为是将http请求跳过到重写的request()
我使用角度4。
答案 0 :(得分:0)
return backend.createConnection(request).response;
private createRequest(backend: ConnectionBackend, request: Request): Observable<Response> {
return backend.createConnection(request).response;
}
...
let responseObservable: any;
if(//some conditions)
responseObservable = httpRequest(this._backend,
new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, <string>url)));
}
return responseObservable;