[英]ngIf with "as" and else
我怎样才能拥有一个带有“as”语法和一个 else 块的 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>
您可以为此目的使用ng-template
。 ng-template 标签永远不会出现在 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
的部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.