I want to make a component that either shows a loading spinner or the content. It's template looks like this
<ng-template [ngIf]="loader.isLoading">
<div class="loader">
<div><span class="fas fa-circle-notch fa-spin fa-4x"></span></div>
<ul>
<li *ngFor="let m of loader.messages">{{m}}</li>
</ul>
</div>
</ng-template>
<ng-template [ngIf]="!loader.isLoading">
<ng-content></ng-content>
</ng-template>
and its called like this
<loader [loader]="loader">
Now we have loaded: {{ theThingThatWasLoading }}.
</loader>
However, the <ng-content>
template is rendered in all cases. Why is the ngIf
being ignored? Is there a workaround?
question from:
https://stackoverflow.com/questions/65936892/angular-template-loading-if 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…