2
definma-ui/src/app/api.service.ts

29 lines
608 B
TypeScript
Raw Normal View History

2020-05-20 10:07:34 +02:00
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {LocalStorageService} from 'angular-2-local-storage';
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(
private http: HttpClient,
private storage: LocalStorageService
) { }
get(url) {
return this.http.get(url, this.authOptions());
}
private authOptions() {
const auth = this.storage.get('basicAuth');
if (auth) {
return {headers: new HttpHeaders({Authorization: 'Basic ' + auth})};
}
else {
return {};
}
}
}