Hello!
I'm currently learning about signals in Angular and experimenting with triggering API calls when a signal value changes.
Here's my setup:
- I have a
numberIdsignal that increments each time a button is clicked. - My goal is to trigger a new API call each time
numberIdchanges to fetch data based on the updated value.
Here's the challenge:
I tried using computed to monitor numberId and placed toSignal inside the computed function to handle the API call, but I'm getting an NG0602 error. The Angular documentation mentions that toSignal shouldn't be used inside computed directly, but I'm not sure about the best practice to handle this pattern.
Could anyone help clarify the correct way to use toSignal to achieve this? Or is there an alternative approach I should take for reactive API calls based on signal changes? Any insights or examples would be much appreciated!
stackblitz example :- https://stackblitz.com/edit/stackblitz-starters-ixrehb?file=src%2Fmain.ts
Thank you!