import { HttpClient } from '@angular/common/http' ; import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { Product } from './../models/product' ; @ Injectable ( { providedIn : 'root' } ) export class ProductService { constructor ( private http ) { } load ( ) { return this . http . get < Product [ ] > ( 'assets/data/products.json' ) ; } search ( searchQuery ) { return this . load ( ) . pipe ( map ( ( list ) => list . filter ( ( value ) => value . name . toLowerCase ( ) . indexOf ( searchQuery . toLowerCase ( ) ) > - 1 ) ) ) ; } }