Add services
This commit is contained in:
54
src/service/product.service.ts
Normal file
54
src/service/product.service.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
interface InventoryStatus {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface Product {
|
||||
id?: string;
|
||||
code?: string;
|
||||
name?: string;
|
||||
description?: string;
|
||||
price?: number;
|
||||
quantity?: number;
|
||||
inventoryStatus?: InventoryStatus;
|
||||
category?: string;
|
||||
image?: string;
|
||||
rating?: number;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ProductService {
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
getProductsSmall() {
|
||||
return this.http.get<any>('assets/demo/data/products-small.json')
|
||||
.toPromise()
|
||||
.then(res => res.data as Product[])
|
||||
.then(data => data);
|
||||
}
|
||||
|
||||
getProducts() {
|
||||
return this.http.get<any>('assets/demo/data/products.json')
|
||||
.toPromise()
|
||||
.then(res => res.data as Product[])
|
||||
.then(data => data);
|
||||
}
|
||||
|
||||
getProductsMixed() {
|
||||
return this.http.get<any>('assets/demo/data/products-mixed.json')
|
||||
.toPromise()
|
||||
.then(res => res.data as Product[])
|
||||
.then(data => data);
|
||||
}
|
||||
|
||||
getProductsWithOrdersSmall() {
|
||||
return this.http.get<any>('assets/demo/data/products-orders-small.json')
|
||||
.toPromise()
|
||||
.then(res => res.data as Product[])
|
||||
.then(data => data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user