M
M
Millerish2020-11-23 20:04:28
Angular
Millerish, 2020-11-23 20:04:28

RxJs: how to send request with new data?

Good time of the day!

I have this code:

contractState = this.http.get(this.apiGetAddressData.getValue().href).pipe(
    repeatWhen(() => this.contractRefresh$),
    switchMap((data: ContractDataModel) => {
      console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!',this.apiGetAddressData.getValue().href, data)
      ...
    }),
    ...


I change apiGetAddressData and send the contractRefresh$ event, but the request always goes to the old url (although the console.log shows the new one).

Why is this happening and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2020-11-23
@Xuxicheta

exactly the opposite :)

this.contractRefresh$.pipe(
  switchMap(() => this.apiGetAddressData),
  switchMap(addressData => this.http.get(addressData.href)),
  ....
)

however, with this organization, the request will be executed both when this.contractRefresh$ is emitted and this.apiGetAddressData is emitted, which I think is acceptable in your case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question