[英]how to reference ng-template from ng-container with if expression
[英]How to use ng-container and ng-template
如果* ngIf返回true,我想提供另一個徽標。
為此,我創建了一個ng-template,並希望在ng-container中顯示它。
不幸的是,我現在無法做到。 我究竟做錯了什么?
這是我的ng-template:
<ng-template *ngIf="customLogo" #customHeader>
<ng-container *myHeader>
<img src="{{customSrc}}}" alt="..." class="">
</ng-container>
</ng-template>
在這里我想用它:
<nav *navItems>
<ng-container *ngTemplateOutlet="customHeader"></ng-container>
<ng-container *ngFor="let bc of bcases">
// Some other stuff..
</ng-container>
</nav>
我剛剛發現我無法在ng-template中嵌入ng-container。
我這樣解決了:
<ng-container *ngIf="customLogo">
<ng-container *myHeader>
<img src="{{customLogoSrc}}" alt="" class="">
</ng-container>
</ng-container>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.