My customized Http service includes a method that handles requests with a loading indicator that displays when the request begins and hides when it ends.
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();
});
}
Although the loading indicator shows and hides accordingly, I want to have control over which requests trigger the loader. How can I accomplish this?
The RequestOptionsArgs interface defines various properties, but using them to determine when to show the loading indicator may not be ideal.
export interface RequestOptionsArgs {
url?: string;
method?: string | RequestMethod;
search?: string | URLSearchParams;
headers?: Headers;
body?: any;
withCredentials?: boolean;
responseType?: ResponseContentType;
}
What alternatives do I have in order to selectively show or hide the loading indicator?