Napster2210 / ngx-spinner

A library for loading spinner for Angular 4 - 17.
https://napster2210.github.io/ngx-spinner/
MIT License
819 stars 138 forks source link

Interceptor Support #275

Open kesavamoorthi-gk opened 7 months ago

kesavamoorthi-gk commented 7 months ago

Instead of incorporating NgxSpinnerService individually in each component, implement a feature to utilize NgxSpinnerService within an Interceptor to eliminate redundancy.

Et3rnal commented 4 months ago

You don't need to add it to every component, just add it to your AppComponent and enable it on router events

eg:

    ngOnInit() {
        this.router.events.pipe(
            filter(
                (e) =>
                    e instanceof NavigationStart ||
                    e instanceof NavigationEnd ||
                    e instanceof NavigationCancel ||
                    e instanceof NavigationError
            ),
            map((e) => e instanceof NavigationStart)
        ).pipe(
            //takeUntil(this.Destroy$),
            //delay(100)
            )
            .subscribe(
                isRouteLoading => {
                    this.isLoading = isRouteLoading;
                },
            );
    }