http request called more than once when biding to view with `async` Pipe
See original GitHub issueRunning watchQuery
with a query, and use the observable returned from the request this way, inside a component:
const obs = this.apollo.watchQuery(...);
this.c$ = obs.map(data => data.a.b.c);
this.d$ = obs.map(data => data.a.b.d);
Then, in the template, I am using:
<div>
C Value: {{ $c | async }}
D Values: {{ $d | async }}
</div>
And it causing the apollo-client to execute the http request of the query twice.
I found a temporary workaround:
const obs = this.apollo.watchQuery(...).publishCount(1).refCount();
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Angular - Observable with async pipe used multiple times in ...
Using the async pipe makes handling subscriptions much easier. It automatically handles unsubscribing unlike subscribing in the component.
Read more >http request called more than once when biding to view with ...
Running watchQuery with a query, and use the observable returned from the request this way, inside a component: const obs = this.apollo.
Read more >How to avoid multiple async pipes in Angular | by Yury Katkov
Use ngIf trick for observable expansion and combine it with grouping the observable into a single object.
Read more >Angular pitfall: Multiple HTTP requests with RxJS and ...
Each async pipe triggers a new HTTP request, because each result$ | async creates a new subscription/stream to the result$ Observable.
Read more >AsyncPipe - Angular
The async pipe subscribes to an Observable or Promise and returns the latest value it has emitted. When a new value is emitted,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dotansimha I also think that the best thing is to call
publish()
orshare()
yourself, this way you give the user the freedom to what ever he wants with his RxObserverOkay, I discussed the issue with @darkbasic and it seems like it has been fixed since then.
Reproduction:
If some of you can create a test or even a simple reproduction please @mention me here so I reopen.