File

app/core/services/loading-indicator.service.ts

Index

Properties
Methods

Constructor

constructor()

Methods

Public hide
hide()
Returns : void
Public loadingDone
loadingDone()
Returns : void
Public show
show()
Returns : void
Public startLoading
startLoading()
Returns : void

Properties

contentLoaderState
Default value : this.contentLoaderSubject.asObservable()
Private contentLoaderSubject
Default value : new Subject<boolean>()
searchLoaderState
Default value : this.searchLoaderSubject.asObservable()
Private searchLoaderSubject
Default value : new Subject<boolean>()
import { Subject } from 'rxjs';
import { Injectable } from '@angular/core';

/*
	This service it used to show/hide the loading spinner. Each component that does a search operation has this service
	injected. Before performing the search operation, they call the show() method to show the loading spinner.

	The loaderState observable is subscribed to in the SearchTabsComponent and that's where the actual spinner is located in the html.
	When a search result is received in the SearchComponent, it will call the hide() method of the service, so that the spinner disappears.

	The show() method must always be called before doing a search operation (either with select(), doSearch() or doSearchWithParameters()),
	otherwise the spinner might get stuck. Timeout has been set to disable loading spinner after 2seconds.
	This is because if you make the same search twice, the JS API won't return a result.
	Therefore the spinner will wait for a result forever if nothing arrives. Disabling it after a timeout mitigates this.
*/

@Injectable()
export class LoadingIndicatorService {

	private searchLoaderSubject = new Subject<boolean>();
	searchLoaderState = this.searchLoaderSubject.asObservable();

	private contentLoaderSubject = new Subject<boolean>();
	contentLoaderState = this.contentLoaderSubject.asObservable();

	constructor() { }

	public show() {
		this.searchLoaderSubject.next(true);
		setTimeout(() => {
			if (this.searchLoaderState) { this.searchLoaderSubject.next(false); }
		}, 5000);
	}
	public hide() {
		this.searchLoaderSubject.next(false);
	}

	public loadingDone() {
		this.contentLoaderSubject.next(false);
	}

	public startLoading() {
		this.contentLoaderSubject.next(true);
	}
}

result-matching ""

    No results matching ""