4

When using ngIf with the asterisk, we can do the following:

<ng-container *ngIf="obj | async as result">{{result}}</ng-container>

How can we do the same with ng-template?

<ng-template [ngIf]="(obs | async) as result">
    {{result}}
</ng-template>

The above code throws.

undefined
  • 6,366
  • 12
  • 46
  • 90

1 Answers1

4

Yeah, you can also use this syntax in ng-template as follows:

<ng-template [ngIf]="obs | async" let-result="ngIf">
   {{result}}
</ng-template>

or

<ng-template [ngIf]="obs | async" let-result>
   {{result}}
</ng-template>

For more details see:

yurzui
  • 205,937
  • 32
  • 433
  • 399