我正在使用Slick Slider(https://github.com/kenwheeler/slick)在我的网页底部显示一个水平滑块:
<div class="container" ng-if="loop">
<div class="row">
<slick dots="true" init-onload="true" data="schedule" center-mode="false" infinite="false" speed="300" slides-to-show="4" touch-move="true" slides-to-scroll="1" class="slider one-time">
<div ng-repeat="x in schedule">
<div class="status-x-current">
<a class="x-button" ng-if="x.title == ''" data-ng-click="showRes(workplace, x)">Click here to to do something</a>
<h3 ng-if="x.title != ''" id = "x_title1" class="x-slider-title">Titel: {{x.title}}</h3>
<h3 ng-if="x.title != ''" id = "x_time1" class="x-slider-time">{{x.date}}</h3>
</div>
</div>
</slick>
</div>
ng-repeat(schedule)的输入数据每10秒从服务器重新加载一次,如下所示:
(function tick() {
ScheduleService.getReservation({}, function(response) {
$scope.schedule = response.schedule;//I already determined that the response is correct and the same every time
$timeout(tick, 10000);
});
})();
这很好,重新加载前2次计划,但在第三次之后它给了我以下错误:
TypeError: Cannot read property 'insertBefore' of null
at angular.js?body=1:3851
at forEach (angular.js?body=1:304)
at Object.$AnimateProvider.$get.enter (angular.js?body=1:3850)
at angular.js?body=1:18726
at publicLinkFn (angular.js?body=1:5421)
at ngRepeatAction (angular.js?body=1:18724)
at Object.$watchCollectionAction [as fn] (angular.js?body=1:11300)
at Scope.$get.Scope.$digest (angular.js?body=1:11396)
at Scope.$get.Scope.$apply (angular.js?body=1:11635)
at done (angular.js?body=1:7636)(anonymous function) @ angular.js?body=1:9038$get @ angular.js?body=1:6649$get.Scope.$digest @ angular.js?body=1:11408$get.Scope.$apply @ angular.js?body=1:11635done @ angular.js?body=1:7636completeRequest @ angular.js?body=1:7802xhr.onreadystatechange @ angular.js?body=1:7758
我100%确定每次重新加载时的时间表都完全相同。我认为这是因为init-onload="true" data="schedule"
。从html中删除该行后不会发生错误。但是删除该行会导致浮油行为不正确。在删除init-onload="true" data="schedule"
时,Slick会将所有幻灯片放入屏幕,而不是仅显示4(slide-to-show =“4”)。