Angular ng-repeat不能与我的数组一起使用

时间:2021-11-22 12:45:03

I have three jsFiddles that demonstrate my problem: 1)Not working 2)Shows the array 3)Working with small array

我有三个jsFiddles来演示我的问题:1)不工作2)显示数组3)使用小数组

<div style="display:inline-block;">
    <div ng-repeat="date in [0,1,2,3]" ng-bind="date" class="day"></div>
</div>

Part of my controller:

我控制器的一部分:

$scope.month_calendar = function (num) {
    var arr = [];
    for (var i = 0; i < 12; i++) {
        arr.push($scope.year_calendar.slice(i * 35, (i + 1) * 35));
$scope.monthly_calendar = $scope.month_calendar($scope.month);

I am trying to make a calendar with ng-repeat where the dates are repeated. When I use a short little arbitrary array it works. When I use the monthly_calendar array it doesn't work, but I can also just print out the monthly_calendar array and it changes when the month changes. Does anyone know why my array won't work in ng-repeat?

我正在尝试使用ng-repeat创建一个日历重复的日历。当我使用一个短的小任意数组时,它的工作原理。当我使用monthly_calendar数组时,它不起作用,但我也可以打印出monthly_calendar数组,并在月份更改时更改。有谁知道为什么我的数组不能用于ng-repeat?

1 个解决方案

#1


2  

AngularJS does not allow duplicates in ng-repeat directive. To fix that use the following:

AngularJS不允许在ng-repeat指令中重复。要修复它,请使用以下内容:

... ng-repeat="date in monthly_calendar track by $index" ...

#1


2  

AngularJS does not allow duplicates in ng-repeat directive. To fix that use the following:

AngularJS不允许在ng-repeat指令中重复。要修复它,请使用以下内容:

... ng-repeat="date in monthly_calendar track by $index" ...