B
B
beduin012015-11-12 10:20:16
Angular
beduin01, 2015-11-12 10:20:16

How to properly implement a nested loop in AngularJS?

<div class="container" ng-controller="TestQuestions">
    <div id="row" ng-repeat="question in questions">
      <div ng-repeat="answer in question.answer">
          <p></p>
        <h4 class="page-header">{{question.id}}. {{question.question}}</h4>
        <p></p>
        <button type="button" class="btn btn-info" value="Input Button">{{answer}}</button>
      </div>
    </div>
  </div>

app.controller("TestQuestions", function($scope) 
  {
    $scope.questions =
    [
      {
        id: 1, question: "Sex?", "sex": {"m":"male", "f":"female"}
      },

      {
        id: 2, question: "Level of your organization", answer: ["Personal", "Federal", "Privat"]
      },

      {
        id: 3, question: "What is your name?", answer: ["Dima", "Roma", "Masha"]
      },
      {
        id: 4, question: "Where do you live?", answer: ["Moscow", "London", "Minsk"]
      }
    ];
  } 

  );

The problem is that this loop gives me a column:
2. Level of your organization
Personal
2. Level of your organization
Federal
2. Level of your organization
Privat
I need
2. Level of your organization
Personal Federal Privat

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2015-11-12
@beduin01

<div id="row" ng-repeat="question in questions">
        <h4 class="page-header">{{question.id}}. {{question.question}}</h4>
        <span ng-repeat="answer in question.answer">
            <button type="button" class="btn btn-info" value="Input Button">{{answer}}</button>
      </span>
    </div>

_
_ _, 2015-11-12
@AMar4enko

<div class="container" ng-controller="TestQuestions">
    <div id="row" ng-repeat="question in questions">
    <h4 class="page-header">{{question.id}}. {{question.question}}</h4>
      <div ng-repeat="answer in question.answer">
          <p></p>
        
        <p></p>
        <button type="button" class="btn btn-info" value="Input Button">{{answer}}</button>
      </div>
    </div>
  </div>

Computer Since, yeah

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question