2018-11-11 13:50:37 +01:00

26 lines
858 B
TypeScript

import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve } from "@angular/router";
import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs/Observable";
import 'rxjs/Rx';
import { environment } from "../../../environments/environment";
import { ErrorCategory } from "../shared";
@Injectable()
export class ErrorCategoryService implements Resolve<false|Array<ErrorCategory>> {
private url = environment.apiUrl + '/api/error-category';
constructor(private httpService: HttpClient) {
}
public resolve(route: ActivatedRouteSnapshot): Promise<false|Array<ErrorCategory>> {
return this.getList().toPromise().then(result => result ? result : false);
}
public getList(): Observable<ErrorCategory[]> {
return this.httpService.get<ErrorCategory[]>(this.url);
}
}