Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 优化/加速AngularJS HTML呈现-性能问题_Javascript_Html_Angularjs_Performance - Fatal编程技术网

Javascript 优化/加速AngularJS HTML呈现-性能问题

Javascript 优化/加速AngularJS HTML呈现-性能问题,javascript,html,angularjs,performance,Javascript,Html,Angularjs,Performance,这可能不是关于这个话题的第一个问题,但因为我花了几个小时才发现我找不到一个好的解决方案,我还是想问你们 我想优化下面的代码,因为页面现在需要几秒钟才能加载。如果我将该部分从页面中取出(它只是页面的一部分),则页面最多加载1秒 仅供参考:对于我测试应用程序的学生,我只有4条路线 <tr ng-repeat="route in student.itin"> <td> <select ng-options="airline._id as ai

这可能不是关于这个话题的第一个问题,但因为我花了几个小时才发现我找不到一个好的解决方案,我还是想问你们

我想优化下面的代码,因为页面现在需要几秒钟才能加载。如果我将该部分从页面中取出(它只是页面的一部分),则页面最多加载1秒

仅供参考:对于我测试应用程序的学生,我只有4条路线

<tr ng-repeat="route in student.itin">
      <td>
         <select ng-options="airline._id as airline.code for airline in ::airlines | orderBy: 'code'" ng-model="route.airline" class="form-control"/>
      </td>
      <td>
         <input type="text" ng-model="route.flight_number" maxlength="4" size="4" class="form-control"/>
      </td>
      <td>
         <input type="text" ng-model="route.class" maxlength="1" size="1" class="form-control"/>
      </td>
      <td>
         <select ng-options="airport._id as airport.code for airport in ::airports | orderBy: 'code'" ng-model="route.departure.airport" class="form-control"/>
      </td>
      <td>
         <div class="form-group has-feedback" ng-class="{'has-error': route.arrival.date < route.departure.date}">
             <input type="text" class="form-control" is-open="datepickers['departure_date' + $index]" max-date="route.arrival.date" timepicker-options="timepicker_options" ng-focus="open($event, 'departure_date'+$index)" datetime-picker="{{ ::datetimepicker_format }}" ng-model="route.departure.date" />

             <span ng-if="route.arrival.date < route.departure.date" tooltip-placement="right" tooltip="Arrival Date cannot be before Departure Date" tooltip-trigger="mouseenter" class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>
         </div>
      </td>
      <td>
         <select ng-options="airport._id as airport.code for airport in ::airports | orderBy: 'code'" ng-model="route.arrival.airport" class="form-control"/>
      </td>
      <td>
         <div class="form-group has-feedback" ng-class="{'has-error': route.arrival.date < route.departure.date}">
             <input type="text" class="form-control" is-open="datepickers['arrival_date' + $index]" min-date="route.departure.date" timepicker-options="timepicker_options" ng-focus="open($event, 'arrival_date'+$index)" datetime-picker="{{ ::datetimepicker_format }}" ng-model="route.arrival.date" />

             <span ng-if="route.arrival.date < route.departure.date" tooltip-placement="right" tooltip="Arrival Date cannot be before Departure Date" tooltip-trigger="mouseenter" class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>
         </div>
      </td>
      <td>
         <input type="text" ng-model="route.filekey" class="form-control"/>
      </td>
      <td class="text-right">
         <a class="btn btn-danger" ng-click="deleteRoute($index)" tooltip-placement="top" tooltip="Delete route" tooltip-trigger="mouseenter">
              <i class="fa fa-trash-o"></i>
         </a>
      </td>
</tr>

我从研究中了解到,我不应该使用太多的ng repeat,尝试最小化数据绑定和过滤器。但在应用了我所学的一切之后,我想到了上面的代码,不知道如何继续优化,因为这还不够


谢谢

如果你的AngularJS高于1.4.1,请尝试改进
ng repeat

  • 曲目按
    添加到您的ng repeat中
  • 尽可能拆下滤清器
  • 一起使用一次性绑定:

或者切换到ReactJS。

您可以尝试使用sly repeat指令代替ng repeat:

谢谢。上面的代码是AngularJS 1.3.15。你到底推荐什么跟踪功能?Sly Repeat目前不适用于Angular 1.3.x。但还是要谢谢你!