79153626

Date: 2024-11-03 21:01:00
Score: 0.5
Natty:
Report link

To do the toSignal update or refresh, you could use the BehaviorSubject.

enter image description here

This code

 
 product.service.ts
================================
 public product_url = "http://127.0.0.1:8000/api/notes"

  getProducts_(): Observable<any> {
    return this.apiService.get(this.product_url);
  }

product-list.component.ts
================================
 private refresh$ = new BehaviorSubject<void>(undefined);
  dataList$=this.refresh$.pipe(switchMap(()=>this.productService.getProducts_()))
  dataSignal = toSignal(this.dataList$)
  refreshAdd() {
    this.refresh$.next();
  }
<table class="table table-hover">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">Product name</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let product_data of dataSignal(); let i = index">
      <th scope="row">{{i+1}}</th>
      <td>{{product_data.title}}</td>
    </tr>
  </tbody>
</table>

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Jorge Jhovani Valverde León