Israel Lavi | b2a3ace | 2018-08-07 10:54:17 +0300 | [diff] [blame^] | 1 | import { Injectable, Type, ComponentRef } from '@angular/core'; |
| 2 | import { LoaderComponent } from './loader.component'; |
| 3 | |
| 4 | @Injectable() |
| 5 | export class LoaderService { |
| 6 | |
| 7 | constructor() {} |
| 8 | |
| 9 | private mainLoaderName = 'general'; |
| 10 | |
| 11 | public registeredLoaders = {}; |
| 12 | |
| 13 | public register(name: string, loader: LoaderComponent) { |
| 14 | if (!this.registeredLoaders[name]) { |
| 15 | this.registeredLoaders[name] = loader; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | public unregister(name: string) { |
| 20 | if (this.registeredLoaders[name]) { |
| 21 | delete this.registeredLoaders[name]; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | public activate(name: string = this.mainLoaderName) { |
| 26 | if (this.registeredLoaders[name]) { |
| 27 | this.registeredLoaders[name].activate(); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | public deactivate(name: string = this.mainLoaderName) { |
| 32 | if (this.registeredLoaders[name]) { |
| 33 | this.registeredLoaders[name].deactivate(); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | } |