Skip to content

ngrxLet with multiple observables #3272

Answered by markostanimirovic
yringler asked this question in Q&A
Discussion options

You must be logged in to vote

@yringler

The ngrxLet directive works with single Observable. Two ways to avoid nested ng-containers:

  1. Combine multiple Observables with combineLatest operator:
@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$ });
}
  1. Use ngIf + ngrxPush:
@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);
  

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yringler
Comment options

Answer selected by yringler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants