-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathconfig.service.ts
46 lines (44 loc) · 1.33 KB
/
config.service.ts
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
38
39
40
41
42
43
44
45
46
import { throwError as observableThrowError, Observable } from "rxjs";
import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
/**
* Retrieve json files from the loopback form
* folder that relates to the model in question
* @export
* @class ConfigService
*/
@Injectable()
export class ConfigService {
url = "assets/models/";
// public activeConfig: ReplaySubject<any> = new ReplaySubject(1);
constructor(private http: HttpClient) {}
/**
* return a json file for the matching file
* or an error if not found
* @param {string} filename
* @returns {Observable<any>}
* @memberof ConfigService
*/
getConfigFile(filename: string): Observable<any> {
return new Observable((observer) => {
this.http
.get(this.url + filename + ".json", { observe: "response" })
.subscribe(
(res) => {
if (res["status"] === 200) {
observer.next(res);
observer.complete();
} else {
console.log("not found");
observableThrowError(new Error("No config file found"));
}
},
(error) => {
// observer.next(error);
// observer.complete();
observableThrowError(new Error("No config file found"));
},
);
});
}
}