我已經擴展HTTP服務和覆蓋方法如如何在請求中提供Angular 2中的自定義RequestOptionsArgs?
request(url: string|Request, options?: RequestOptionsArgs): Observable<Response>
在該請求方法我有一個裝載機,我展示和當請求的開始和在請求結束隱藏。
request(url: string|Request, options?: RequestOptionsArgs): Observable<Response> {
this.loadingService.start();
if (!options) {
options = {};
options.headers = new Headers();
}
this.updateHeaders(options.headers);
if (typeof url !== 'string') {
this.updateHeaders(url.headers);
}
return super.request(url, options)
.catch((response: Response) => this.authError(response))
.finally(() => {
this.loadingService.done();
});
}
loadingService啓動和停止加載指示器。但我不希望此加載指示符顯示在所有請求上。我想要一些請求不顯示加載器。我怎樣才能做到這一點?
的RequestOptionArgs是一個接口
export interface RequestOptionsArgs {
url?: string;
method?: string | RequestMethod;
search?: string | URLSearchParams;
headers?: Headers;
body?: any;
withCredentials?: boolean;
responseType?: ResponseContentType;
}
但我可能不應該使用這些變量作爲告知是否要顯示加載指示器的方式。
我該怎麼辦?
包裝原始Http服務而不擴展可能是最好的方法,謝謝。 – Alex