简体   繁体   English

将值加载到ng-if指令中的AngularJS计时

[英]AngularJS timing on loading values into ng-if directive

I am using an few ng-if directives on elements while details about them are loading. 我正在对元素使用一些ng-if指令,同时正在加载有关它们的详细信息。 This is so I can show a user a loader graphic while the element value is undefined. 这样,我可以向用户显示未定义元素值的加载程序图形。 When the value gets defined the ng-if equates to false and hides itself. 定义该值时,ng-if等于false并隐藏自身。

Following that another ng-if equates to true which looks for the value being instantiated to some value. 之后,另一个ng-if等于true,它将查找要实例化为某个值的值。

<span ng-if="signboard.activeSlideshowId && signboard.activeSlideshowId!=0 && signboard.activeSlideshowId!='failed' && signboard.activeSlideshowName!='failed'"><a href="#/slideshows/{{ signboard.activeSlideshowId }}">{{ signboard.activeSlideshowName }}</a></span>
<span ng-if="signboard.activeSlideshowId==undefined"><i class="fa fa-spin fa-spinner"></i></span>
<span ng-if="signboard.activeSlideshowId=='failed' || signboard.activeSlideshowName=='failed'" class="text-warning">Failed</span>
<span ng-if="signboard.activeSlideshowId==0">No Active Slideshow</span>

The value in this ng-if takes some time to be populated leaving the space blank for a few noticeable moments. 此ng-if中的值需要花费一些时间来填充,因此在空白处留出了一些明显的时间。 I can only take this to be that the ng-if adds these new elements to the dom and only on the following internal run of $scope.$apply() will these values be updated in the UI. 我只能认为ng-if将这些新元素添加到dom中,并且仅在$ scope。$ apply()的以下内部运行中才会在UI中更新这些值。

加载角度ng

How can I make it that these transitions are smoother to the user, so that there isnt so much time inbetween the elements being displayed. 如何使这些过渡对用户更平滑,从而使显示的元素之间没有太多时间。 I chose ng-if over ng-show because the page will contain a list of items and each column contains a value which needs to be individually populated from an asynchronous call. 我选择ng-if而不是ng-show,因为该页面将包含项目列表,并且每一列都包含一个值,该值需要通过异步调用单独进行填充。 I am under the impression that too many ng-show/ng-hide calls on a page would really hamper performance. 我的印象是,页面上太多的ng-show / ng-hide调用确实会影响性能。

您可以将ngHide与one time binding

<span ng-hide="::signboard.activeSlideshowId"><i class="fa fa-spin fa-spinner"></i></span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM