Estava fazendo em cima desse exemplo: http://www.freakyjolly.com/angular-8-7-show-global-progress-bar-loader-on-http-calls-in-3-steps-using-angular-interceptors-in-angular-4-3/
mas não funcionou.
Segue meu código:
comum.module.ts
import { CommonModule } from "@angular/common"; import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http"; import { NgModule } from "@angular/core"; import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { AuthInterceptor } from "../security/interceptor/auth.interceptor"; import { DialogSimNaoComponent } from './dialog/dialog-sim-nao/dialog-sim-nao.component'; import { LoaderComponent } from './loader/loader.component'; import { MaterialModule } from "./material-module/material.module"; import { LoaderService } from './services/loader.service'; import { SnackBarComponent } from './snack-bar/snack-bar.component'; const modules = [ CommonModule, MaterialModule, FormsModule, ReactiveFormsModule, HttpClientModule ]; @NgModule({ imports: [...modules], declarations: [SnackBarComponent, DialogSimNaoComponent, LoaderComponent], providers: [ LoaderService, SnackBarComponent, { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true } ], entryComponents: [DialogSimNaoComponent], exports: [...modules] }) export class ComumModule { }
app.module.ts
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ComponentService } from './component.service';
import { ComumModule } from './core/comum.module';
import { SecurityModule } from './security/security.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
ComumModule,
SecurityModule
],
providers: [ComponentService],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
bootstrap: [AppComponent]
})
export class AppModule { }
loader.service.ts
import { Injectable } from "@angular/core"; import { BehaviorSubject } from "rxjs"; @Injectable({ providedIn: "root" }) export class LoaderService { public isLoading = new BehaviorSubject(false); constructor() { } }