I write a http intercpetor,it is like this:
import { Injectable, Inject } from '@angular/core';
import { SlimLoadingBarService } from 'ng2-slim-loading-bar';
// ... other imports in here
@Injectable()
export class HttpInterceptorService extends Http {
private apiEndpoint: string;
constructor(
@Inject(CONFIG_TOKEN) config: Config,
private backend: ConnectionBackend,
private defaultOptions: RequestOptions,
private slimLoadingBarService: SlimLoadingBarService
) {
super(backend, defaultOptions);
this.apiEndpoint = config.apiEndpoint;
}
get(url: string, options?: RequestOptionsArgs): Observable<any> {
this.beforeRequest();
return super.get(this.getFullUrl(url), this.requestOptions(options))
// ...
}
private beforeRequest(): void {
// this is not work
this.slimLoadingBarService.start();
}
// ... other methods
}
My app.module provide config like this:
{
provide: HttpInterceptorService,
useFactory: (backend: XHRBackend, defaultOptions: RequestOptions) => {
return new HttpInterceptorService(CONFIG, backend,
defaultOptions, new SlimLoadingBarService);
},
deps: [XHRBackend, RequestOptions]
}
Now, this Http interceptor is worker,But the SlimLoadingBarService
doew not work.
I feel should be wrong to pass the new SlimLoadingBarService
lead, but the direct transmission SlimLoadingBarService
, the same will be given, and now stuck in this place do not know how to continue.
There is no error message, but loadingbar( SlimLoadingBarService
) does not show up.
Try this instead.
{
provide: HttpInterceptorService,
useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, slimLoadingBarService: SlimLoadingBarService) => {
return new HttpInterceptorService(CONFIG, backend,
defaultOptions, slimLoadingBarService);
},
deps: [XHRBackend, RequestOptions, SlimLoadingBarService]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.