How can you convert an array to an observable array in angular 6. I am trying to return an observable while having an array. I'm doing this so that instead of an HTTP request I can return hard-coded data.
I have the following interface:
export interface IProduct {
productId: number;
productName: string;
productCode: string;
releaseDate: string;
description: string;
price: number;
starRating: number;
imageUrl: string;
}
Then I have this service:
export class ProductService {
products: IProduct[];
getProducts(): Observable<IProduct[]> {
this.products = [
{
'productId': 2,
'productName': 'Black cat',
'productCode': 'GDN-001',
'releaseDate': 'March 18, 2018',
'description': 'Can punch peoples faces.',
'price': 32.00,
'starRating': 5,
'imageUrl': 'https://placekitten.com/400/420'
},
{
'productId': 3,
'productName': 'T Cat',
'productCode': 'GDN-002',
'releaseDate': 'March 18, 2018',
'description': 'Can shoot guns.',
'price': 32.00,
'starRating': 2.2,
'imageUrl': 'https://placekitten.com/400/420'
}
];
//paste here how to return the array to observable
}
}