[英]overlap divs for ngif else Angular4
I'm subscribed to an stream to get some data from a third party API and while that's happening I display a div with a spinning wheel kind of stuff. 我订阅了一个流以从第三方API获取一些数据,而这种情况发生时,我显示了一个带有纺车类东西的div。 Once I have the data then that data is replacing that div.
一旦有了数据,该数据将替换该div。 I have that with an
ngif else
: 我有一个
ngif else
:
<div *ngIf="my-data;else loading" class="my-data-container">
...
</div>
<ng-template #loading>
<div class="loading-container">
shows the loading spinning wheel
</div>
</ng-template>
the problem I have is that for a really short period of time both divs appear on the screen and they make an strange effect like a small blip. 我的问题是,在很短的时间内,两个div都出现在屏幕上,并且它们产生了类似小斑点的奇怪效果。 I would like them to overlap each other otherwise they appear one under the other.
我希望它们彼此重叠,否则它们会彼此重叠。 Can I achieve that via code or do I need to investigate a css trick for it?
我可以通过代码来实现,还是需要研究一个CSS技巧?
Use container as ngif template instead of div it self 使用容器作为ngif模板,而不是自己使用div
<ng-container *ngIf="my-data;else loading">
<div class="my-data-container">
...
</div>
</ng-container>
<ng-template #loading>
<div class="loading-container">
shows the loading spinning wheel
</div>
</ng-template>
Make sure you declare my-data
value as null
at the start and change ngIf
syntax to use then
: 确保在开始时将
my-data
值声明为null
并更改ngIf
语法以使用then
:
<div *ngIf="my-data; then #content; else loading" class="my-data-container">
</div>
<ng-template #content>
show this content after loading
</ng-template
<ng-template #loading>
<div class="loading-container">
shows the loading spinning wheel
</div>
</ng-template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.