@ngx-loading-bar/http-client
Version:
Automatic page loading / progress bar for Angular
60 lines (55 loc) • 2.12 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { LoadingBarService, LoadingBarModule } from '@ngx-loading-bar/core';
import { Injectable, NgModule } from '@angular/core';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { tap, finalize } from 'rxjs/operators';
var LoadingBarInterceptor = /** @class */ (function () {
function LoadingBarInterceptor(loader) {
this.loader = loader;
}
LoadingBarInterceptor.prototype.intercept = function (req, next) {
// https://github.com/angular/angular/issues/18155
if (req.headers.has('ignoreLoadingBar')) {
return next.handle(req.clone({ headers: req.headers.delete('ignoreLoadingBar') }));
}
var started = false;
var ref = this.loader.useRef('http');
return next.handle(req).pipe(tap(function () {
if (!started) {
ref.start();
started = true;
}
}), finalize(function () { return started && ref.complete(); }));
};
LoadingBarInterceptor.ctorParameters = function () { return [
{ type: LoadingBarService }
]; };
LoadingBarInterceptor = __decorate([
Injectable(),
__metadata("design:paramtypes", [LoadingBarService])
], LoadingBarInterceptor);
return LoadingBarInterceptor;
}());
var LoadingBarHttpClientModule = /** @class */ (function () {
function LoadingBarHttpClientModule() {
}
LoadingBarHttpClientModule = __decorate([
NgModule({
imports: [HttpClientModule, LoadingBarModule],
exports: [HttpClientModule, LoadingBarModule],
providers: [
{
provide: HTTP_INTERCEPTORS,
useClass: LoadingBarInterceptor,
multi: true,
},
],
})
], LoadingBarHttpClientModule);
return LoadingBarHttpClientModule;
}());
/**
* Generated bundle index. Do not edit.
*/
export { LoadingBarHttpClientModule, LoadingBarInterceptor as ɵa };
//# sourceMappingURL=ngx-loading-bar-http-client.js.map