Angularjs ng-repeat渲染的项目比数组中的项目多



我目前有以下代码:

<div class="carousel" ng-if="novedadesEmpleados.cumpleanosDeHoy.length">
<div ng-repeat="empleado in novedadesEmpleados.todaysBirthdays" carousel-renderer class="event-card">
<birthday-card empleado="empleado" card-notifier></birthday-card>
</div>
</div>

这曾经工作得很好,直到我从使用引导轮播改为小滑块。

该数组目前有 2 个元素,但是 HTML 渲染了 6, 4 oh,它们只显示默认的 angularjs 文本(大括号中的属性名称(,另外 2 个显示正确的信息。

可能是什么原因造成的?这两个指令用于在完成渲染后调用 Tiny Slider 初始值设定项:

angular.module('PortalIntranet').directive('cardNotifier', function ($timeout) {
return function(scope, element, attrs){
if(scope.$last)
scope.$emit('FinishedRendering'); 
}
});
angular.module('PortalIntranet').directive('carouselRenderer', function ($timeout) {
return function (scope, element, attrs) {
scope.$on('FinishedRendering', function (event) {
var slider = tns({
container: '.card-slider',
autoplay: true,
slideBy: 'page',
autoplayTimeout: 3500,
speed: 750,
autoplayButton: false,
nav: false,
autoplayButtonOutput: false,
controls: false
});
console.log(slider);
});
}
});

Angular 不太可能显示比数组中更多的项目。 首先,确保您的数据是干净的。

我相信根源;)你的问题出在指令和根范围内。 最有可能的是,当条件在 rootScope 或"carouselRenderer"的作用域上满足时,而不是在"cardNotifier"的作用域上,您需要进行检查。 即

if (scope.$parent.$last) 

您希望父范围中的最后一个重复项。

另外,作为旁注,请确保您的 css 类位于正确的位置。 为什么"活动卡"在轮播渲染器上而不是在生日贺卡上?

最新更新