Declarative Data Access Pattern

PHOTO EMBED

Fri Dec 16 2022 16:19:38 GMT+0000 (Coordinated Universal Time)

Saved by @ilivanilton #angular #rxjs

// app.component.html
<div *ngIf="products$ | async as products">
  <button *ngFor='let product of products'>
  	{{ product.name }}
  </button>
</div>

// app.component.ts
products$ = this.productService.products$;

// app.service.ts
products$ = this.http.get<Product[]>(this.url)
  .pipe(
  	tap(console.log),
  	catchError(this.handleError)
   );
content_copyCOPY

busca por dados ao carregar o component.

https://youtu.be/uv_sblwIJag?t=221