import { Injectable } from '@angular/core'; import { DataSourceService } from './data-source.service'; import { FileOptions, FileOptionsClass } from '../model/files'; @Injectable({ providedIn: 'root', }) export class FilesService { private data: FileOptions[]; // private loading = false; constructor( private dataSource: DataSourceService, ) { this.data = []; this.initData(); } initData() { return new Promise((resolve, reject) => { this.dataSource.getAllFiles().subscribe( data => { if (this.data.length >= 0) { this.data.splice(0, this.data.length); } data.forEach(file => { this.data.push(new FileOptionsClass(file)); }); resolve(data); }, ); }); } getAllFiles(): Promise { return new Promise(async (resolve, reject) => { // if (this.data.length === 0) { // } await this.initData(); resolve(this.data); }); } }