如何从Angular InMemoryDbService DB获取数据

时间:2018-11-07 13:38:41

标签: angular typescript

如何使用InMemoryDbServicehttpClient的ID中仅获取一种产品:

export class InMemoryDataService implements InMemoryDbService {
    createDb() {
        const cateogry = [
            {
                id: 1, name: 'Mr. Nice', descriptio: 'dasdad', image: "sada", product: [
                    { id: 0, name: 'Milos', descriptio: "sdada", number: 1, image: 'ssad' },
                ]



            },
            {
                id: 2, name: 'Misko', descriptio: 'dasdad', image: "sada", product: [
                    { id: 0, name: 'Milos', descriptio: "sdada", number: 1, image: 'ssad' },
                    { id: 1, name: 'Somi', descriptio: "haha", number: 1, image: 'haha' }
                ]
            }

        ];
        return { cateogry };
    }

    genId(cateogry: CategoryModel[]): number {
        return cateogry.length > 0 ? Math.max(...cateogry.map(hero => hero.id)) + 1 : 11
    }

要从我的服务中通过此方法获取所有数据:

 getCategoryMemory(): Observable<ProductModel[]> {
return this.http.get<ProductModel[]>(this.cateogryUrl).pipe(
  catchError(this.handleError('getProduct', []))
)


 }

这种方法在我的朋友中:

 getProduct() {
this.dataStorageServiceService.getProduct(2).subscribe(product => {
  this.productArray = product
  console.log('Misko' + this.productArray)
})


}

0 个答案:

没有答案