Home To display results of 2 ng-repeats alternately

# To display results of 2 ng-repeats alternately

manishk
1#
manishk Published in 2018-01-12 17:53:45Z
 I need the values returned from {{compNames}} and {{compDesc}} to print alternately, like a top-down stack. But with the 2 ng-repeats I'm not able to get it in that format. 
{{compNames}}
{{compDesc}}
 If I print out {{$ctrl.data}}, I get the following- { "details": { "comp": { "id": "12345", "company_name": "Google", "date_created": "2018-01-10 18:03:27", "file_name":"Admin.txt" } }, "compNames": ["five","nine","twelve"], "compDesc": [" String combinations"," String combinations"," String manipulation to eval"] }  I checked a similar thread and tried to do something like the following but I think it's the wrong approach and doesn't work for me (hence I have given the$ctrl.data output as well)- 
{{data.compNames}}
{{data.compDesc}}

Nikolaj Dam Larsen
2#
Nikolaj Dam Larsen Reply to 2018-01-12 18:58:58Z
 One solution is to do a zip-operation on the two arrays beforehand in your controller and then iterate over the resulting array. Something like this: ctrl.combined = ctrl.data.compNames.map(function(value, index){ return { name: value, desc: ctrl.data.compDesc[index] }; });  and then iterate over it like this: 
{{comp.name}} {{comp.desc}}
{{comp.name}}
{{comp.desc}}
 or in case you had something else in mind when you said alternating, you can do something like this:   Beware that you need to add extra logic to the map-function, in case you expect the two arrays to be of different lengths. But based on your data, it doesn't seem like that'll be an issue.
NTP
3#
 if length of your compNames is equal to compDesc, you can use length in your ng-repeat to iterate length many times js $scope.getNumber = function() { return new Array($scope.data.compNames.length); }  html 
{{data.compNames[$index]}} {{data.compDesc[$index]}}
 demo