1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

How to acces HttpContextToken declared in a library?

Discussão em 'Angular' iniciado por R3N0, Setembro 17, 2024.

  1. R3N0

    R3N0 Guest

    I have an HttpInterceptor to show a progressbar when I'm making an http call.

    intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
    if (request.context.get(SHOW_PROGRESSBAR)) {
    this.requestLoaderService.show();
    this.pendingRequestNumber++;

    return next.handle(request).pipe(
    delay(0),
    finalize(() => {
    this.pendingRequestNumber--;

    if (this.pendingRequestNumber === 0) {
    this.requestLoaderService.hide();
    }
    }),
    );
    }
    }


    This HttpInterceptor is in an Angular library. I would like to set the value of an HttpContextToken (SHOW_PROGRESSBAR) in my Angular app.

    this.http.request<KweResponse<any>>(
    method,
    this.url.getString(endpoint),
    {
    body,
    headers: options?.headers,
    params: options?.params,
    observe: 'response',
    context: new HttpContext()
    .set(SHOW_PROGRESSBAR, options?.withProgressbar ?? true)
    }
    )


    How can I declare the HttpContextToken in my library for it to be accessible from my app?

    Continue reading...

Compartilhe esta Página