Multiple ng-repeat on single element

前端 未结 5 415
慢半拍i
慢半拍i 2020-12-11 03:17

Is this possible to achieve a code like this:-


       {{data}} {{value}}
 
<         


        
5条回答
  •  有刺的猬
    2020-12-11 03:57

    Angular ng-repeat does not support it but still you can write your own custom directive according to your requirements.

    Update Section

    var traverseCollection = angular.module("CollectionTraverse", []);
    
    traverseCollection.directive("repeatCollection", function(){
    
        return {
            restrict: "A",
            scope: {
                model: "="
            },
            controller: controller: function($scope) {
                var collectionList = $scope.model;
    
                angular.forEach(collectionList, function(obj, index) {
                    angular.forEach(obj, function(data, index) {
    
                    });
                });
            }
        }
    });
    
    Your scope should contains the list of your collection objects : $scope.collectionList = [dataArray, valueArray];
    
    Usage in HTML:
    -------------------------------------------
    

    This directive will be generic to traverse list of collections and yes in the above code there can be some syntactical errors because i did not run it. Its your luck.

提交回复
热议问题