如何使用"as“语法和其他块拥有一个ngIf?
<div class="customer-form-container" *ngIf="(customer$ | async) as customer; else elseBlock">
<div class="customer-not-found-container" #elseBlock>
<h1>customer not found</h1>
</div>
发布于 2021-12-13 11:04:44
为此,您可以使用ng-template
。ng模板标记从未出现在DOM中,但您可以使用它来定义可以与结构指令结合使用的模板。例如,在ngIf
的else语句中。
<div *ngIf="(customer$ | async) as customer; else elseBlock">
<!-- you can use "customer" here -->
</div>
<ng-template #elseBlock>
<div class="customer-not-found-container">
<h1>customer not found</h1>
</div>
</ng-template>
您还可以阅读更多关于结构指令(例如,ngIf
) 这里的内容。还有一个关于ng-template
的章节。
https://stackoverflow.com/questions/70339607
复制