如何防止在AngularJS初始化之前显示元素(ng-show) [英] How to prevent element show before AngularJS initialized( ng-show )

查看:155
本文介绍了如何防止在AngularJS初始化之前显示元素(ng-show)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AngularJS中,我想知道如何防止ng-show生效之前页面上显示的元素,我发现一些有关ng-cloak的帖子,但在我的情况下似乎不起作用,可能是ng-cloak用于防止双花括号而不是元素样式.

In AngularJS, I wonder how to prevent the elements shown on page before ng-show take effect, I found some posts talk about ng-cloak, but it seems not work in my case, probably the ng-cloak is for prevent double curly bracket rather than Element style.

另一种谈论方式是在AngularJS初始化之前为它定义某种样式,但这很难管理.

Another way someone talk about is define some style for before AngularJS initialized, but that is kinda hard to manage.

有官方的方法可以解决这个问题吗?

Is there some official way to handle this?

推荐答案

除非要显示加载程序,否则ng-cloak应该是您的解决方案.

Unless you want to show a loader, ng-cloak should be your solution.

有关ng-cloak的官方文档

如果仍然存在问题,则可以尝试在HTML中添加css来隐藏带有ng-cloak的元素,以确保浏览器能够及时找到它.

If you still have the issue, you may try to add the css to hide element with ng-cloak inside your html to be sure the browser has it in time.

如果这样做,请选择添加ng-cloak的方式. 例如,将其添加为类:

If you do that, choose on way to add the ng-cloak. For example add it as class:

<div ng-show="condition" class="ng-cloak">...</div>

并将其添加到您的html头标记中:

And add this into your html head tag:

<style> .ng-cloak { display: none !important; } </style>

这篇关于如何防止在AngularJS初始化之前显示元素(ng-show)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆