0

I tried using ng-repeat value,group1,group2

i'm getting

grp1

grp2

abc

def

value1

value2

I need

grp1

  abc

     valu1                           

grp2

      def

          valu1  

Html:
<ul>
<li ng-repeat="heading in group1"> {{heading}} </li> // heading
<li ng-repeat="subheading in group2"> {{subheading }} </li> // sub heading
<li ng-repeat="val in value"> {{val}} </li> // value
</ul>



JavaScript:

                             $scope.group1 = [grp1,grp2];
                             $scope.group2 = [abc,def];
                             $scope.value = [value1,value2];   
1
  • suggest you map your data into nested arrays that fit your tree structure in desired markup. Will find it a lot easier to manage. Should provide more real world examples of data. What is shown is far too primitive to be of much assistance with mapping. Start with models that make sense Commented Nov 13, 2013 at 13:58

3 Answers 3

1

use $index to get other sub values

 <div ng-repeat="eachval in group1">
   <p>{{ eachval }}</p>
   <p style="margin-left:15px">{{ group2[$index]}}</p>
   <p style="margin-left:25px">{{ value[$index]}}</p>
 </div>

Here is the WORKING FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

0

You should use a single array with three different keys

$scope.arrayList = [{group1Name : 'grp1',group2Name: 'abc', valueName: 'val1'},
{group1Name : 'grp2',group2Name: 'def', valueName: 'val2'}]

htlm would look like this

<li ng-repeat="group in arrayList">
    <div>{{group.group1Name}}</div>
    <div>{{group.group2Name}}</div>
    <div>{{group.valueName}}</div>
</li>

You can write a simple javascript to modify your 3 arrays in 1 array. Hope this helps

2 Comments

This is not help full for me. my data will be in arrays only and group1Name,group2Name,valueName these are heavy data, when more values will be
I was thinking of an organised approach, but if so is the case use $index as mentioned above by folks above. Cheers :)
0

Use ng-repeat start and end points to iterate the first array, then use $index to reference the other elements:

<ul>
    <li ng-repeat-start="heading in group1">{{heading}}</li> // heading
    <li> {{group2[$index]}} </li> // sub heading
    <li ng-repeat-end> {{val[$index]}} </li> // value
</ul>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.