import { Injectable } from '@angular/core';

@Injectable({
    providedIn: 'root'
})
export class SharedDataService {

    public static data: any[] = [];
    constructor() { }
    /*public getSharedData(key: string) {
        return SharedDataService.data[key];
    }
    */
    public getSharedData(key: string, remove = true) {
        const selectedData = SharedDataService.data[key];
        if (remove) {
            this.removeData(key);
        }
        return selectedData;
    }
    public setSharedData(data: any, key: string) {
        SharedDataService.data[key] = data;
    }
    public clearAll() {
        SharedDataService.data = [];
    }
    public removeData(key: string) {
        delete SharedDataService.data[key];
    }

    public showAll() {
        for (const v of SharedDataService.data) {
            console.log(v);
        }
    }
}
