import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { Observable } from 'rxjs/Observable' ; export interface Product { id : number ; title : string ; price : number ; imageUrl : string ; description : string ; } @ Injectable ( ) export class ProductService { constructor ( private http ) { } getAll ( ) { return this . http . get < Product [ ] > ( '/data/products.json' ) ; } getById ( productId ) { return this . http . get < Product [ ] > ( '/data/products.json' ) . map ( products => < Product > products . find ( p => p . id === productId ) ) ; } }