< div>即使在角度js中ng-show为false也会在一段时间内可见 [英] <div> is visible for some time even if ng-show is false in angular js
问题描述
有这个div:
<div ng-show="messageAvailable" class="message">
<p ng-bind="message"></p>
</div>
该messageAvailable来自$ http请求.因此,直到angular js加载并且该请求发送响应并将值'false'分配给$ scope.messageAvailable为止,该div才可见.我不希望即使一小段时间也能看到它.
that messageAvailable comes from $http request. So, until angular js loads and that request sends response and assigns the value 'false' to $scope.messageAvailable, this div is visible. I don't want it to be visible even for a small period of time.
我尝试过:
<div ng-show="a=messageAvailable || false" class="message">
<p ng-bind="message"></p>
</div>
和这个(在控制器的最开始):
and this(at the very beginning of the controller):
$scope.messageAvailable = false;
都没有帮助.
推荐答案
您是否尝试过使用ng-if代替ng-show?
Have you tried using ng-if instead of ng-show?
ng-if如果表达式为false,则不会渲染其中的HTML节点.至少使用Angular 1.3或更高版本.
ng-if won't render the HTML nodes within if the expression is false. At least with Angular 1.3 or later.
<div ng-if="messageAvailable" class="message">
<p ng-bind="message"></p>
</div>
通常,您应该在ng-show/hide上考虑ng-if,尤其是在ng-repeat内部时.它将大大减少摘要周期中活动手表的数量,并加快应用程序的速度.
In general you should consider ng-if over ng-show/hide, especially when inside an ng-repeat. It will greatly reduce the number of active watches in the digest cycle and speed up the application.
这篇关于< div>即使在角度js中ng-show为false也会在一段时间内可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!