import { HttpEvent , HttpHandler , HttpInterceptor , HttpRequest } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs' ; import { finalize } from 'rxjs/operators' ; import { BusyService } from './busy.service' ; @ Injectable ( ) export class BusyHttpInterceptor implements HttpInterceptor { constructor ( private busyService ) { } intercept ( request , next ) { this . busyService . setBusy ( true ) ; return next . handle ( request ) . pipe ( finalize ( ( ) => { this . busyService . setBusy ( false ) ; } ) ) ; } }