ngOnInit
case of the entire component, because there I can hide the spinner at the end of the inner most subscribe()
function. All good. Now: There are many filter options on the page and some take quite a long time until the page fully shows the updates. There I've got problems, because I can't find a proper place to hide the spinner after showing it e.g. when the user clicks one of the filter buttons. Hints are welcome. Demo 1: Go to http://preview.owasp-juice.shop/#/score-board (spinner working on initialization) - Demo 2: On the page click any of the two "Hide/Show all" buttons to see how rendering takes long on "Show all" without a spinner. There I'd really like to add one but can't find the right hook to hide it. Any hint or help welcome! (If you send a PR with a working solution, I'll happily send you a Juice Shop sticker pack! :smile:)
ngx-spinner
first paste below script to your package.json:
"scripts": {
"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
}
}
ngx-spinner
and check again
hi guys, any idea why spinner is not being hide on finalize?
a.component.ts
ngAfterViewInit() {
this.subscriptions.add(
this.organizationsService.organizations$
.pipe(
tap(() => {
this.spinnerService.showLoader();
}),
finalize(() => {
this.spinnerService.hideLoader();
}),
takeUntil(this.destroySubject))
.subscribe(response => {
this.cachedFacts = this.cachedFacts.concat(response);
if (!this.searchService.search.value.length) {
this.dataSource.data = this.cachedFacts as IOrganizations[];
this.dataSource.sort = this.sort;
} else {
this.dataSource.data = response as IOrganizations[];
this.cachedFacts = [];
}
this.filterSelectObj.filter((o) => {
o.options = this.getFilterObject(this.dataSource.data, o.columnProp);
});
}, (error) => {
this.errorService.handleError(error);
})
);
}
spinner.service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { NgxSpinnerService } from 'ngx-spinner';
@Injectable()
export class SpinnerService {
constructor(private spinnerService: NgxSpinnerService) { }
public showLoaderSubject = new BehaviorSubject<boolean>(false);
showLoader() {
// this.showLoaderSubject.next(true);
this.spinnerService.show();
}
hideLoader() {
// this.showLoaderSubject.next(false);
this.spinnerService.hide();
}
}
spinner.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SpinnerComponent } from './spinner.component';
import { NgxSpinnerModule, NgxSpinnerService } from 'ngx-spinner';
import { SpinnerService } from '@shared/services/spinner.service';
@NgModule({
imports: [
CommonModule,
NgxSpinnerModule
],
declarations: [SpinnerComponent],
exports: [SpinnerComponent],
providers: [SpinnerService, NgxSpinnerService]
})
export class SpinnerModule { }