MurhafSousli / ngx-progressbar

Angular progress bar ☄
https://ngx-progressbar.netlify.app/
MIT License
1.02k stars 101 forks source link

Progressbar only show once #59

Closed eanfs closed 7 years ago

eanfs commented 7 years ago

I'm submitting a Question (check one with "x")

[ ] bug report => search for a similar issue before submitting
[ ] feature request
[ X] question

my customer HttpProvider

import { Injector } from '@angular/core';
import { Http, XHRBackend, RequestOptions } from '@angular/http';
import { JhiEventManager, JhiInterceptableHttp } from 'ng-jhipster';

import { AuthInterceptor } from './auth.interceptor';
import { LocalStorageService, SessionStorageService } from 'ng2-webstorage';
import { AuthExpiredInterceptor } from './auth-expired.interceptor';
import { ErrorHandlerInterceptor } from './errorhandler.interceptor';
import { NotificationInterceptor } from './notification.interceptor';
import { NgProgressService } from 'ngx-progressbar';

export function interceptableFactory(
    backend: XHRBackend,
    defaultOptions: RequestOptions,
    localStorage: LocalStorageService,
    sessionStorage: SessionStorageService,
    injector: Injector,
    eventManager: JhiEventManager,
    progressService: NgProgressService
) {
    return new JhiInterceptableHttp(
        backend,
        defaultOptions,
        [
            new AuthInterceptor(localStorage, sessionStorage, progressService),
            new AuthExpiredInterceptor(injector),
            // Other interceptors can be added here
            new ErrorHandlerInterceptor(eventManager),
            new NotificationInterceptor(injector)
        ]
    );
};

export function customHttpProvider() {
    return {
        provide: Http,
        useFactory: interceptableFactory,
        deps: [
            XHRBackend,
            RequestOptions,
            LocalStorageService,
            SessionStorageService,
            Injector,
            JhiEventManager,
            NgProgressService,
        ]
    };
};
import { Observable } from 'rxjs/Observable';
import { RequestOptionsArgs, Response } from '@angular/http';
import { LocalStorageService, SessionStorageService } from 'ng2-webstorage';
import { JhiHttpInterceptor } from 'ng-jhipster';
import { NgProgressService } from 'ngx-progressbar';

export class AuthInterceptor extends JhiHttpInterceptor {

    constructor(
        private localStorage: LocalStorageService,
        private sessionStorage: SessionStorageService,
        private progressService: NgProgressService
    ) {
        super();
    }

    requestIntercept(options?: RequestOptionsArgs): RequestOptionsArgs {
        console.log(Date.now);
        this.progressService.start();
        const token = this.localStorage.retrieve('authenticationToken') || this.sessionStorage.retrieve('authenticationToken');
        if (!!token) {
            options.headers.append('Authorization', 'Bearer ' + token);
        }
        return options;
    }

    responseIntercept(observable: Observable<Response>): Observable<Response> {
        return observable.finally(() => {
            console.log(Date.now);
            this.progressService.done();
        }); // by pass
    }

}

the progressbar only show when page first loading ,

MurhafSousli commented 7 years ago

Hi @eanfs It is unclear what you are trying to accomplish with this! If you want to have the progress bar to start and end when with your Http requests, then use the new NgProgressInterceptor plug.

Update to 2.0.4 first and then check the README for the usage

jigarpt commented 6 years ago

@eanfs Could you achieve this with jhister? can you please share the steps?

Thanks.