#Question about toSignal()

5 messages · Page 1 of 1 (latest)

sage bronze
#

Hello everyone, I was wondering if I could use toSignal as a computed signal.
For example, I have and observable that gets data from the server, and I want it to trigger everytime a state signal changes. This is what I tried:

data = toSignal(httpObservable(stateSignal()));

I was assuming toSignal would act like a computed signal. But it doesn't update when stateSignal() changes. Is it possible to have a computed signal from a observable that updates when their signal dependences change?

thorny spade
#
 httpObservable$ = toObservable(this.stateSignal).pipe(
    switchMap((stateSignalData) => this.api.get(stateSignalData.cats))
  );
 data = toSignal(this.httpObservable$);
#

what do you guys think ? x)

#

Just edited it so it match the names you used in your example

sage bronze
#

Nice!! I just tried it and it works, thank you 🙂