import { from, Observable } from 'rxjs';
import { share, shareReplay } from 'rxjs/internal/operators';

export class HeaderService {

    public profileObservable;

    constructor(

        private http: HttpClient) {

    }

    getProfile(): Observable {

        if (this.profileObservable) {

            return this.profileObservable;

        } else {

            this.profileObservable = this.http.get(environment.APIEndpoint + 'userProfile').pipe(shareReplay());

            this.profileObservable.subscribe(res = & gt; this.setUserProfileData(res));

            return this.profileObservable;

        }

    }

}