Try to use within forkJoin, get issue to display in html. #104
-
|
So 1 is all good, can see both get requested at the same time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
You are trying to Okay what is happening there, let me explain. By the looks of it you've wrapped the get To say it basically, you cant wrap the both queries into a forkJoin. You need to put the forkJoin into a export class Service {
...
public getTodos() {
return this._http.get(`...`);
}
public getUsers() {
return this._http.get(`...`);
}
}
@Component({
standalone: true,
imports: [NgIf, NgForOf, AsyncPipe],
template: `
<ng-container *ngIf="(queryUsersAndTodos$ | async) as usersAndTodos">
<div *ngIf="usersAndTodos.isLoading">Loading...</div>
<p *ngIf="usersAndTodos.isError">Error...</p>
<ul *ngIf="usersAndTodos.isSuccess">
<li *ngFor="let item of usersAndTodos.data">
{{ item.users | json }}
{{ item.todos | json }}
</li>
</ul>
</ng-container>
`,
})
export class Component {
private _service = inject(Service); // the one from above
private _useQuery = inject(UseQuery);
public queryUsersAndTodos$ = this._useQuery(['todosAndUsers'], () => {
return forkJoin({
users: this._service.getTodos(),
todos: this._service.getUsers()
}).pipe(/* do some mapping if you want */)
})
} |
Beta Was this translation helpful? Give feedback.

You are trying to
forkJointwo QueryResults together, this is the problem.Okay what is happening there, let me explain. By the looks of it you've wrapped the get
userand gettodosinto aUseQueryand now you are trying toforkJoinboth theuserandtodosquery together.forkJoinis constructed to await all observables (until they've pushed something) that it got passed to, but in order, but what now happens is that as soon as they get called, they'll likely emit a value which is kept inside the wrappedUseQueryand therefore it emits this update to theforkJoin, but what also happens is that both observables will close as soon as they have emitted once.To say it basically, you cant wra…