我正在使用Slick Slider(https://github.com/kenwheeler/slick)在我的网页底部显示一个水平滑块:
<div class="container" ng-if="schedule.length>0">
<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>
</div>
这在(重新)加载页面的开始时工作正常,但数据源“schedule”每分钟从服务器更新一次,并且在“schedule”更新后我得到以下错误并且该按钮不起作用:
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
如果我从html代码中删除“光滑”的大头钉,问题就不再发生了,所以我和Slick有关,但我不确定究竟是什么问题以及如何解决它。
答案 0 :(得分:1)
我开玩笑说float
。将ng-if='ctrl.isDataLoaded'
添加到您的块中,这样只有在controller
获取正确的数据后才会初始化。这应该可以解决您实际丢失数据的问题,直到它有用。