mirror of
https://github.com/akveo/ngx-admin.git
synced 2026-01-15 22:15:30 +01:00
feat(preloader): preloader service which can take a list of promises and execute smth once all promises are completed
This commit is contained in:
parent
02fdd09bc0
commit
d1f368e571
6 changed files with 63 additions and 4 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import {Component, ViewChild, ViewEncapsulation, Input, Output, ElementRef, EventEmitter} from '@angular/core';
|
||||
|
||||
import {BaThemePreloader} from '../../../theme/services';
|
||||
|
||||
import './baAmChart.loader.ts';
|
||||
import {BaAmChartThemeService} from './baAmChartTheme.service';
|
||||
|
||||
|
|
@ -18,6 +20,7 @@ export class BaAmChart {
|
|||
@ViewChild('baAmChart') private _selector:ElementRef;
|
||||
|
||||
constructor (private _baAmChartThemeService:BaAmChartThemeService) {
|
||||
this._loadChartsLib();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
|
@ -28,4 +31,12 @@ export class BaAmChart {
|
|||
let chart = AmCharts.makeChart(this._selector.nativeElement, this.baAmChartConfiguration);
|
||||
this.onChartReady.emit(chart);
|
||||
}
|
||||
|
||||
private _loadChartsLib():void {
|
||||
BaThemePreloader.registerLoader(new Promise((resolve, reject) => {
|
||||
AmCharts.ready(function(){
|
||||
resolve('AmCharts ready');
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
src/app/theme/services/baImageLoader/index.ts
Normal file
1
src/app/theme/services/baImageLoader/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from './baImageLoader.service.ts';
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class BaThemePreloader {
|
||||
|
||||
private static _loaders:Array<Promise<any>> = [];
|
||||
|
||||
public static registerLoader(method:Promise<any>):void {
|
||||
BaThemePreloader._loaders.push(method);
|
||||
}
|
||||
|
||||
public static clear():void {
|
||||
BaThemePreloader._loaders = [];
|
||||
}
|
||||
|
||||
public static load():Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
BaThemePreloader._executeAll(resolve);
|
||||
});
|
||||
}
|
||||
|
||||
private static _executeAll(done:Function):void {
|
||||
setTimeout(() => {
|
||||
Promise.all(BaThemePreloader._loaders).then((values) => {
|
||||
done.call(null, values);
|
||||
|
||||
}).catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
1
src/app/theme/services/baThemePreloader/index.ts
Normal file
1
src/app/theme/services/baThemePreloader/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from './baThemePreloader.service.ts';
|
||||
2
src/app/theme/services/index.ts
Normal file
2
src/app/theme/services/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from './baImageLoader';
|
||||
export * from './baThemePreloader';
|
||||
Loading…
Add table
Add a link
Reference in a new issue