mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2025-04-19 15:29:18 +00:00
28 lines
725 B
TypeScript
28 lines
725 B
TypeScript
import {Injectable} from '@angular/core';
|
|
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
|
import process from 'process';
|
|
import {Product} from './models/product';
|
|
import {Observable, of} from 'rxjs';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class ApiService {
|
|
apiUrl = 'https://backend.betterzon.xyz';
|
|
|
|
constructor(
|
|
private http: HttpClient
|
|
) {
|
|
}
|
|
|
|
getProducts(): Observable<Product[]> {
|
|
try {
|
|
const prods = this.http.get<Product[]>((this.apiUrl + '/products'));
|
|
console.log(prods);
|
|
return prods;
|
|
} catch (exception) {
|
|
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
|
|
}
|
|
}
|
|
}
|