shumih / ng-http-events

Angular interceptor for information about request pending state

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NgHttpEvents

The library is an angular interceptor service

Install

To install the package run:

npm i @shumih/ng-http-events

Usage

provide service as Angular Interceptor in root module

@NgModule({
  providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useExisting: HttpEventsService,
      multi: true,
    },
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

and inject HttpEventsService wherever you want:

export class AppComponent {
  public isWeatherRequestPending$ = this.httpEvents.getPending(HttpEventsService.urlEndsWith('/weather'));
  public isCityInfoUpdateRequestPending$ = this.httpEvents.getPending(
    req => req.method === 'PUT' && HttpEventsService.urlEndsWith('/city')(req)
  );

  constructor(private httpEvents: HttpEventsService) {}
}

About

Angular interceptor for information about request pending state


Languages

Language:TypeScript 85.2%Language:JavaScript 10.6%Language:HTML 3.4%Language:CSS 0.8%