Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 间隔和循环的Ng重复中的Ng重复_Angularjs_Ng Repeat - Fatal编程技术网

Angularjs 间隔和循环的Ng重复中的Ng重复

Angularjs 间隔和循环的Ng重复中的Ng重复,angularjs,ng-repeat,Angularjs,Ng Repeat,我想在ng repeat中进行ng repeat,并在第一次ng repeat的每3项之后显示第二次ng repeat的结果。当第二次ng重复的数据不足时,我想重新开始,直到第一次ng重复完成 阵列: 项目=[ “第1项”、“第2项”、“第3项”、“第4项”、“第5项”、“第6项”、“第7项”、“第8项”、“第9项”、“第10项” ] 条=[ “BAR1”、“BAR2” ]一种解决方案是创建一个新的数组,并每隔三个索引插入条元素: var newArray = []; items.forEa

我想在ng repeat中进行ng repeat,并在第一次ng repeat的每3项之后显示第二次ng repeat的结果。当第二次ng重复的数据不足时,我想重新开始,直到第一次ng重复完成

阵列:

项目=[
“第1项”、“第2项”、“第3项”、“第4项”、“第5项”、“第6项”、“第7项”、“第8项”、“第9项”、“第10项”
]
条=[
“BAR1”、“BAR2”

]
一种解决方案是创建一个新的数组,并每隔三个索引插入
元素:

var newArray = [];

items.forEach(function (item, index) {
    if (index % 3 === 0) {
       // bars.shift() will remove the first element of bars and return it
       newArray.push(bars.shift());
    }

    newArray.push(item);
});

然后您可以在
newArray
ng repeat
,如果您在ng repeat中对项目进行迭代之前建立项目列表,可能会更简单,如下所示:

var myApp=angular.module('myApp',[]);
控制器('MyCtrl',['$scope',函数($scope){
$scope.items=[
“第1项”、“第2项”、“第3项”、“第4项”、“第5项”、“第6项”、“第7项”、“第8项”、“第9项”、“第10项”
];
$scope.bar=[
“BAR1”、“BAR2”
];
$scope.allItems=函数(){
var-arr=[],j=0;
$scope.items.forEach(函数(item,idx){
如果(idx>0&&idx%3==0){
arr.push($scope.bar[j%$scope.bar.length]);
j+=1;
}
arr.push(项目);
});
返回arr;
};
}]);

  • {{item}}

如果您想要纯基于模板的内容:

<div ng-repeat="item in items">
    <div>{{item}}</div>
    <div ng-if="($index+1) % 3 === 0">{{bars[ (($index+1) / 3 - 1)%(bars.length) ]}}</div>
</div>

{{item}}
{{bar[($index+1)/3-1)%(bar.length)]}

演示:

这就是我需要的。非常感谢你。