Retrieve Related Data Pattern (Many)

PHOTO EMBED

Wed Dec 21 2022 15:33:13 GMT+0000 (Coordinated Universal Time)

Saved by @ilivanilton #angular #rxjs-pattern

// app.component.html
<div *ngIf="productSuppliers$ | async as suppliers">
 	<div *ngFor="let supplier of suppliers">
		{{ supplier.name }}
	</div>
</div>
 
 
// app.component.ts
productSuppliers$ = this.productService.productSuppliers$;
 
 
// product.service.ts
selectedProduct$ = ...
productSuppliers$ = this.selectedProduct$.pipe(
  switchMap(product =>
	forkJoin(
		product.supplierIds.map(
			supplierId => this.http.get<Supplier>(`${url}/${supplierId}`))
   )
);
content_copyCOPY