admin管理员组文章数量:1431406
On the image, you can see that there are loading spinners next to the numbers.
The DOM element that shows the spinner has ng-if = "gridItem.contentScoreLoadingState == 'loading'"
.
The DOM element that shows the number has ng-if = "gridItem.contentScoreLoadingState == 'loaded'"
.
Code is below:
<i class="fa fa-spin fa-spinner" style="font-size: 12px;" ng-if="gridItem.contentScoreLoadingState=='loading'"></i>
<span ng-if="gridItem.contentScoreLoadingState=='failed'">-</span>
<span ng-if="gridItem.contentScoreLoadingState=='loaded'">{{ gridItem.content_score }}</span>
When loading ends, first the number shows and after a small delay loading spinner disappears. But for an instant both of them appears at the same time and I'm not sure why.
On the image, you can see that there are loading spinners next to the numbers.
The DOM element that shows the spinner has ng-if = "gridItem.contentScoreLoadingState == 'loading'"
.
The DOM element that shows the number has ng-if = "gridItem.contentScoreLoadingState == 'loaded'"
.
Code is below:
<i class="fa fa-spin fa-spinner" style="font-size: 12px;" ng-if="gridItem.contentScoreLoadingState=='loading'"></i>
<span ng-if="gridItem.contentScoreLoadingState=='failed'">-</span>
<span ng-if="gridItem.contentScoreLoadingState=='loaded'">{{ gridItem.content_score }}</span>
When loading ends, first the number shows and after a small delay loading spinner disappears. But for an instant both of them appears at the same time and I'm not sure why.
Share Improve this question edited Jun 27, 2016 at 17:27 Hopeful Llama 7565 silver badges26 bronze badges asked Jun 27, 2016 at 15:13 OguzGelalOguzGelal 7767 silver badges20 bronze badges2 Answers
Reset to default 9I tried to wrap <i..
inside of a wrapper element and moved to ng-if
to there. And it worked. Like this:
<span ng-if="gridItem.contentScoreLoadingState==='loading'"><i class="fa fa-spin fa-spinner" style="font-size: 12px;"></i></span>
<span ng-if="gridItem.contentScoreLoadingState==='failed'">-</span>
<span ng-if="gridItem.contentScoreLoadingState==='loaded'">{{ gridItem.bined_frequency }}</span>
One potential cause could be ngAnimate if you're using that module (grasping at straws, but that's caused me issues in the past).
Regardless, in your situation it probably makes more sense to use a switch:
<span ng-switch="gridItem.contentScoreLoadingState">
<span ng-switch-when="loading"><i class="fa fa-spin fa-spinner" style="font-size: 12px;"></i></span>
<span ng-switch-when="failed">-</span>
<span ng-switch-when="loaded">{{ gridItem.content_score }}</span>
</span>
本文标签: javascriptAngularJS ngif has a strange delayStack Overflow
版权声明:本文标题:javascript - AngularJS ng-if has a strange delay - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745476535a2659989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论