retrieve related data pattern (one)

PHOTO EMBED

Wed Dec 21 2022 15:26:38 GMT+0000 (Coordinated Universal Time)

Saved by @ilivanilton #angular #rxjs-pattern

// app.component.html
<div *ngIf="productSupplier$ | async as supplier">
  	{{ supplier.name }}
  </button>
</div>
 
 
// app.component.ts
productSupplier$ = this.productService.productSupplier$;
 
 
// product.service.ts
selectedProduct$ = ...
productSupplier$ = this.selectedProduct$.pipe(
  switchMap(product => this.http.get<Supplier>(`${url}/${product.supplierId}`))
);
content_copyCOPY