ngrxLet with multiple observables #3272
-
What's best practice if there's a piece of DOM which depends on multiple observables? Is it reccomended to combine the observables in the component with a This should probably be documented in the right place |
Beta Was this translation helpful? Give feedback.
Answered by
markostanimirovic
Dec 29, 2021
Replies: 1 comment 1 reply
-
The
@Component({
template: `
<ng-container *ngrxLet="vm$ as vm">
<p>X: {{ vm.x }}</p>
<p>Y: {{ vm.y }}</p>
</ng-container>
`
})
export class MyComponent {
readonly x$ = of(1);
readonly y$ = of(2);
readonly vm$ = combineLatest({ x: this.x$, y: this.y$ });
}
@Component({
template: `
<ng-container *ngIf="{ x: x$ | ngrxPush, y: y$ | ngrxPush } as vm">
<p>X: {{ vm.x }}</p>
<p>Y: {{ vm.y }}</p>
</ng-container>
`
})
export class MyComponent {
readonly x$ = of(1);
readonly y$ = of(2);
} I suggest the first one. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
yringler
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yringler
The
ngrxLet
directive works with single Observable. Two ways to avoid nested ng-containers:combineLatest
operator:ngIf
+ngrxPush
: