aboutsummaryrefslogtreecommitdiffstats
path: root/src/angular/loader/loader.service.ts
blob: 288f9bd651893fa3a08c43c7f096d998a0b4ceaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Injectable, Type, ComponentRef } from '@angular/core';
import { LoaderComponent } from './loader.component';

@Injectable()
export class LoaderService {

    constructor() {}

    private mainLoaderName = 'general';

    public registeredLoaders = {};

    public register(name: string, loader: LoaderComponent) {
        if (!this.registeredLoaders[name]) {
            this.registeredLoaders[name] = loader;
        }
    }

    public unregister(name: string) {
        if (this.registeredLoaders[name]) {
            delete this.registeredLoaders[name];
        }
    }

    public activate(name: string = this.mainLoaderName) {
        if (this.registeredLoaders[name]) {
            this.registeredLoaders[name].activate();
        }
    }

    public deactivate(name: string = this.mainLoaderName) {
        if (this.registeredLoaders[name]) {
            this.registeredLoaders[name].deactivate();
        }
    }

}