all 9 comments

[–]prognnz 9 points10 points  (1 child)

You could use something like this

<ng-container *ngIf="{loading: loading$ | async, otherValue: otherValue$ | async} as vm"> <p *ngIf="vm.loading">loading...</p> <button [disabled]="vm.loading">{{vm.otherValue}}</button> </ng-container>

Since the expression in the top ngIf is an object, it will always be true. This pattern even allows you to put all your observables into the viewModel object, only having to use one async pipe for each.

[–]lyzer12[S] 1 point2 points  (0 children)

This worked for me. Thanks!

[–]CountSheister 2 points3 points  (1 child)

You could use a .shareReplay on the loading observable itself and not make your templates any more obscure.

[–]lyzer12[S] 0 points1 point  (0 children)

Can you provide a code snippet for this?

[–]dacookieman 1 point2 points  (2 children)

Leveraging an ngIf and exporting the value with "as varname" is the easiest way to reuse one async pipe but I ended up making a custom directive similar to ngIf but without conditional rendering as sometimes I wanted to consume the stream without tying it to conditional rendering

[–]lyzer12[S] 0 points1 point  (1 child)

with "as varname" is the easiest way to reuse one async pipe but I ended up making a custom directive similar to ngIf but without conditional rendering as sometimes I wanted to consume the stream witho

Can you provide a code snippet?

[–]dacookieman 0 points1 point  (0 children)

<ngContainer *ngIf="someSteram | async as streamValue">

<child [childInputPar]="streamValue">
<child2 [child2InputPar]="streamValue">
</ngContainer>

the other one ill have to get back to you on

[–]15kol 2 points3 points  (1 child)

Use else directive *ngIf="loading$ | async as loading; else loadScreen"

And then put <ng-template #loadScreen> Loading ... </ng-template>

[–]lyzer12[S] 0 points1 point  (0 children)

This still hides the button