页面上的许多UI-Bootstrap-Datepickers加载速度非常慢 - 我可以使用单个实例并移动元素吗?

时间:2014-10-04 21:18:01

标签: angularjs angularjs-directive angular-ui-bootstrap

我使用' ng-repeat'显示了很多行。每行有2个UI-Bootstrap-Datepickers。当有很多行时,页面的加载速度非常慢。

我想使用单个日期选择器然后在用户点击的字段下动态移动它,或者可能在点击时加载指令并在选择后再次卸载它。

关于如何实现这一目标的任何想法?

<li ng-repeat="ticket in data.tickets">

    <div ng-click="openAddStartCal($event, ticket)" ng-hide="currentTicketUpdating == ticket.TicketId && currentParameterUpdating =='startCal' && startCalSaving == true">
                        <input type="text"
                               starting-day="2"
                               show-button-bar="false"
                               show-weeks="false"
                               class="form-control addTicketDateInput"
                               datepicker-popup="dd MMM"
                               ng-model="ticket.StartDate"
                               ng-change="saveEditStartDate(ticket)"
                               is-open="checkStartOpened(ticket)"
                               min-date=""
                               max-date="'2015-06-22'"
                               datepicker-options="dateOptions"
                               date-disabled="disabled(date, mode)"
                               ng-required="true"
                               close-text="Close" />
                    </div>
</li>

1 个答案:

答案 0 :(得分:4)

您可以使用ng-switch或ng-if。 Ng-switch / ng-iff实际上会删除它内部的任何东西,直到条件评估为真。

例如:

<li ng-repeat="ticket in data.tickets">
    <div ng-click="openAddStartCal($event, ticket);ticket.openCal = !ticket.openCal" ng-hide="currentTicketUpdating == ticket.TicketId && currentParameterUpdating =='startCal' && startCalSaving == true">
          <div ng-if="ticket.openCal">
                    <input type="text"
                           starting-day="2"
                           show-button-bar="false"
                           show-weeks="false"
                           class="form-control addTicketDateInput"
                           datepicker-popup="dd MMM"
                           ng-model="ticket.StartDate"
                           ng-change="saveEditStartDate(ticket)"
                           is-open="checkStartOpened(ticket)"
                           min-date=""
                           max-date="'2015-06-22'"
                           datepicker-options="dateOptions"
                           date-disabled="disabled(date, mode)"
                           ng-required="true"
                           close-text="Close" />
                </div>
        </div>
</li>

注意ng-click的ticket.openCal = !ticket.openCal添加,然后在ng-if中使用它。 (顺便说一句,ig你在openAddStartCal中有一些有用的东西,你可以使用它。)

或者,您也可以使用类似空的ng-include(直到单击行):

<li ng-repeat="ticket in data.tickets">
    <div ng-click="openAddStartCal($event, ticket);ticket.openCal = !ticket.openCal" ng-hide="currentTicketUpdating == ticket.TicketId && currentParameterUpdating =='startCal' && startCalSaving == true">

      <div ng-include=""></div>
</li>

然后在有点击事件时设置ng-include变量。