0
$scope.radiolabels={
                Name:"",
                type:"radiobtns",
                rbtn:[{
                          Name:"",
                          order:$scope.order
                      }]
                    };

How to iterate objct and its rbtn.I mean in the first div we have to iterate the object and inside that first div we need to iterate the rbtn.I have tried like below.

<ul>


    <li ng-repeat="radiolbs in radiolabels track by $index">
                        RadioButtons {{$index}}: <input type="text" id="ral_{{$index}}" data-ng-model="$parent.radiolabels[$index].Name"/><br>

                                     <div ng-repeat="r in radiolabels.rbtn track by $index">
                                        Option {{$index}}<input type="text" id="rab_{{$index}}"><br>
                                        Option {{$index}}<input type="text" id="rab_{{$index}}"><button class="btn btn-default">+</button>
                                    </div>
                </li>
          </ul>

Its not working

1
  • No but i got it by changing the "r in radiolabels.rbtn track by $index" as "r in radiolbs.rbtn track by $index" Commented Oct 30, 2015 at 10:11

2 Answers 2

1

You are trying to iterate over the object in the outer loop. This isn't going to work, because your object isn't in an array.

Iterating over an array is what will give you the $index variable, otherwise you'll just be iterating over key/value pairs.

You probably want to wrap your outer object inside an array.

$scope.radiolabels = [{
  Name: "",
  type: "radiobtns",
  rbtn: [{
    Name: "",
    order: $scope.order
  }]
}];

Then your logic for the inner loop can be fixed by asking for the property on the currently iterated object.

<ul>
  <li ng-repeat="radiolbs in radiolabels track by $index">
    RadioButtons {{$index}}:
    <input type="text" id="ral_{{$index}}" data-ng-model="radiolbs.Name"/><br>

    <div ng-repeat="r in radiolbs.rbtn track by $index">
      Option {{$index}}<input type="text" id="rab_{{$index}}"><br>
      Option {{$index}}<input type="text" id="rab_{{$index}}">
      <button class="btn btn-default">+</button>
    </div>
  </li>
</ul>
Sign up to request clarification or add additional context in comments.

Comments

0

You can try ng-init for this. like:

<ul>
<li ng-repeat="radiolbs in radiolabels" ng-init="dataIndex = $index">
   RadioButtons {{dataIndex }}: <input type="text" id="ral_{{dataIndex}}" data-ng-model="$parent.radiolabels[dataIndex ].Name"/><br> 
</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.