I have a function called getList()
in the SearchService
:
public getList() {
// HTTP POST call as an observable
// Pipe with a few map transformations
}
When initializing my ListComponent
, I create an Observable like this:
ngOnInit(): void {
list$ = searchService.getList();
}
Then, I subscribe to the observable in the template using the async pipe:
<ng-container *ngIf="list$ | async as list; else showSpinner">
<!-- Content here -->
</ng-container>
Surprisingly, even though this is the only place where I subscribe to the list$
observable, I notice two requests when checking Dev Tools:
https://i.sstatic.net/WTzC1.png
My troubleshooting steps so far:
I've searched similar questions on StackOverflow but none of the answers seem to solve my issue.
Adding
ChangeDetectionStrategy.OnPush
didn't provide a solution either.I've experimented with various methods like
share
,shareReplay
,publishReplay
,refCount
,delay
,debounceTime
,distinctUntilChanged
,take
,first
on thegetList()
function andlist$
observable without success.
What could be causing this unexpected behavior?