Javascript 安圭拉的表演很慢

Javascript 安圭拉的表演很慢,javascript,angularjs,performance,ng-show,angular-ng-if,Javascript,Angularjs,Performance,Ng Show,Angular Ng If,情况: <button class="button" ui-sref="app.section_1" ng-show="section1_data.length > 0">Section 1 </button> 在我的应用程序中,我最多有12个分区。 但并不是每次都要显示所有的数据,这取决于包含相对数据的对象是否为空 在视图中,我检查每个对象,如果对象为空,则不显示相对部分 就这样 问题在于,这会导致在主视图中显示按钮(链接到每个部分)时出现明显延迟。在0,5到1

情况:

<button class="button" ui-sref="app.section_1" ng-show="section1_data.length > 0">Section 1 </button>
在我的应用程序中,我最多有12个分区。 但并不是每次都要显示所有的数据,这取决于包含相对数据的对象是否为空

在视图中,我检查每个对象,如果对象为空,则不显示相对部分

就这样

问题在于,这会导致在主视图中显示按钮(链接到每个部分)时出现明显延迟。在0,5到1秒之间。 那真是太过分了。 如果不显示ng,按钮将立即显示,但我需要进行此检查

问题:

<button class="button" ui-sref="app.section_1" ng-show="section1_data.length > 0">Section 1 </button>
我可以做些什么来加快AngularJs的评估速度

我已经尝试了几种方法进行检查,但延迟仍然是一样的

尝试1-一般功能和ng显示:

<button class="button" ui-sref="app.section_1" ng-show="section1_data.length > 0">Section 1 </button>
使用检查对象是否为空的常规函数:

$scope.isEmpty = function(obj) 
{
    // Return true if empty
    if (obj == null) return true;
    if (obj.length === 0)  return true;

    // Return false if not empty
    if (obj.length > 0)    return false;

    for (var key in obj) 
    {
        if (hasOwnProperty.call(obj, key)) return false;
    }

    return true;
}
观点:

<button class="button" ui-sref="app.section_1" ng-show="!isEmpty(section1_data)">Section 1 </button>
第1节

尝试2-更简单的检查和ng显示:

<button class="button" ui-sref="app.section_1" ng-show="section1_data.length > 0">Section 1 </button>
第1节

尝试3-一般功能和ng如果

<button class="button" ui-sref="app.section_1" ng-if="!isEmpty(section1_data)">Section 1 </button>
<button class="button" ui-sref="app.section_1" ng-if="section1_data.length > 0">Section 1 </button>
第1节

尝试4-简单检查和ng如果

<button class="button" ui-sref="app.section_1" ng-if="!isEmpty(section1_data)">Section 1 </button>
<button class="button" ui-sref="app.section_1" ng-if="section1_data.length > 0">Section 1 </button>
第1节

结论:

<button class="button" ui-sref="app.section_1" ng-show="section1_data.length > 0">Section 1 </button>
对于所有这4次尝试,Angular需要评估的时间是相同的

我真的需要加快这一进程,但我的想法已经没有了。 有人知道我怎样才能做到


谢谢大家!

将ng show/ng hide替换为ng如果

您能提供完整的示例吗?为什么?唯一的区别是ng if有一个独立的作用域。正如您在尝试3和尝试4中看到的那样,我已经尝试过了:)@R.Salisbury,不仅如此,还有-
ng if
not add element to DOM if condition false,ng show-始终添加,只需更改样式