当使用带星号的 ngIf 时,我们可以执行以下操作:
<ng-container *ngIf="obj | async as result">{{result}}</ng-container>
我们如何使用 ng-template 做同样的事情?
<ng-template [ngIf]="(obs | async) as result">
{{result}}
</ng-template>
上面的代码抛出错误。
最佳答案
是的,您也可以在 ng-template 中使用这种语法,如下所示:
<ng-template [ngIf]="obs | async" let-result="ngIf">
{{result}}
</ng-template>
或
<ng-template [ngIf]="obs | async" let-result>
{{result}}
</ng-template>
更多细节见:
关于Angular ng-template 用作语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55299950/