0

I have data in my object of objects but ng-repeat is not showing me anything my data is json Format like:

     {
      "0": [
        {
          "question": "How often is real property re-assessed (or revalued)?",
          "id": 1,
          "section": "Assessment",
          "sectionId": 2,
          "check": true,
          "index": 0
        },
{
          "question": "How often is real property re-assessed (or revalued)?",
          "id": 1,
          "section": "Assessment",
          "sectionId": 2,
          "check": true,
          "index": 0
        },
        {
          "key": "Survey Meta Data"
        }
      ],
      "1": [
        {
          "question": "When are New Assessment Notices sent out?",
          "id": 2,
          "section": "Assessment",
          "sectionId": 2,
          "check": true,
          "index": 1
        },
        {
          "key": "Assessment"
        }
      ]
    }

and I want to display all question and key how can I achieve this I am trying something like this:

<div class="form-group" ng-repeat="data in viewQuestions">
                   <div  ng-repeat="values[$index] in data ">
                   <label for="comment">{{values.questions}}</label>
                   </div>
                   <label for="comment">{{data.key}}</label>
                  <textarea class="form-control" rows="2" id="comment"></textarea>
                  </div>
3
  • how do you want to see the output? Commented Jul 3, 2017 at 6:11
  • I want to see the questions first and then key something like this: Commented Jul 3, 2017 at 6:12
  • Question: How often is real property re-assessed (or revalued)? Question: "How often is real property re-assessed (or revalued)? Key: Survey meta data Question: When are New Assessment Notices sent out Key: Assessment Commented Jul 3, 2017 at 6:13

4 Answers 4

1

remove the $index in your ng-repeat.

also, change the {{values.questions}} to {{values.question}}

<div class="form-group" ng-repeat="data in viewQuestions">
   <div  ng-repeat="values in data "> 
      <label >{{values.question}}</label>
   </div>
   <label for="comment">{{data.key}}</label>
   <textarea class="form-control" rows="2" id="comment"></textarea>
</div> 

Demo

angular.module("app",[])
.controller("ctrl",function($scope){
  $scope.viewQuestions = {
      "0": [
        {
          "question": "How often is real property re-assessed (or revalued)?",
          "id": 1,
          "section": "Assessment",
          "sectionId": 2,
          "check": true,
          "index": 0
        },
{
          "question": "How often is real property re-assessed (or revalued)?",
          "id": 1,
          "section": "Assessment",
          "sectionId": 2,
          "check": true,
          "index": 0
        },
        {
          "key": "Survey Meta Data"
        }
      ],
      "1": [
        {
          "question": "When are New Assessment Notices sent out?",
          "id": 2,
          "section": "Assessment",
          "sectionId": 2,
          "check": true,
          "index": 1
        },
        {
          "key": "Assessment"
        }
      ]
    }

})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 <div class="form-group" ng-repeat="data in viewQuestions"> 
                   <div  ng-repeat="values in data "> 
                   <label >{{values.question}}</label>
                   </div>
                   <label for="comment">{{data.key}}</label>
                  <textarea class="form-control" rows="2" id="comment"></textarea>
                  </div>
</div>

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

Comments

1

Proably you need this,

<div class="form-group" ng-repeat="(key,value) in viewQuestions  track by $index">
  <div  ng-repeat="values in value ">
   <label for="comment">{{values.question}}</label>
   <label for="comment">{{values.key}}</label>
   <textarea class="form-control" rows="2" id="comment"></textarea>
 </div>
</div>

DEMO

var pegasusWebApp = angular.module('ReqWebApp', [])

pegasusWebApp.controller('ReqAppController', function ReqAppController($scope) {
    $scope.viewQuestions = {
  "0": [
    {
      "question": "How often is real property re-assessed (or revalued)?",
      "id": 1,
      "section": "Assessment",
      "sectionId": 2,
      "check": true,
      "index": 0
    },
    {
      "question": "How often is real property re-assessed (or revalued)?",
      "id": 1,
      "section": "Assessment",
      "sectionId": 2,
      "check": true,
      "index": 0
    },
    {
      "key": "Survey Meta Data"
    }
  ],
  "1": [
    {
      "question": "When are New Assessment Notices sent out?",
      "id": 2,
      "section": "Assessment",
      "sectionId": 2,
      "check": true,
      "index": 1
    },
    {
      "key": "Assessment"
    }
  ]
};
});
<!DOCTYPE html>
<html ng-app="ReqWebApp">
<head>
    <meta charset="UTF-8">
    <title>New Request</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-controller="ReqAppController">
    <div class="form-group" ng-repeat="(key,value) in viewQuestions  track by $index">
        <div ng-repeat="values in value ">
            <label for="comment">{{values.question}}</label>
            <label for="comment">{{values.key}}</label>
            <textarea class="form-control" rows="2" id="comment"></textarea>
        </div>
    </div>
</body>
</html>

Comments

0

angular.module("Myapp",[])
.controller("Myctrl",function($scope){
$scope.viewQuestions = {
      "0": [
        {
          "question": "How often is real property re-assessed (or revalued)?",
          "id": 1,
          "section": "Assessment",
          "sectionId": 2,
          "check": true,
          "index": 0
        },
{
          "question": "How often is real property re-assessed (or revalued)?",
          "id": 1,
          "section": "Assessment",
          "sectionId": 2,
          "check": true,
          "index": 0
        },
        {
          "key": "Survey Meta Data"
        }
      ],
      "1": [
        {
          "question": "When are New Assessment Notices sent out?",
          "id": 2,
          "section": "Assessment",
          "sectionId": 2,
          "check": true,
          "index": 1
        },
        {
          "key": "Assessment"
        }
      ]
    }
  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <div ng-app="Myapp" ng-controller="Myctrl">
  <div class="form-group" ng-repeat="(key,val) in viewQuestions  track by $index">
    <div  ng-repeat="v in val ">
        <label for="comment">{{v.question}}</label>
    </div>
    <label for="comment">{{val.key}}</label>
    <textarea class="form-control" rows="2" id="comment">       </textarea>
  </div>
  </div> 

Comments

0

Here is the JsFiddle link

HTML

    <div ng-app="myApp">

      <div ng-controller="ctrl">
        <div ng-repeat="obj in data">
          <div ng-repeat="item in obj">
            <label ng-if="item.question">Question:{{item.question}}</label>
            <label ng-if="item.key">Key: {{item.key}}</label>
            <br>
            <textarea ng-if="item.key" class="form-control" rows="2" id="comment">
            </textarea>
            <hr>
          </div>

        </div>
      </div>
    </div>

JS Code

  var app = angular.module('myApp', []);

  app.controller('ctrl', function($scope) {
    $scope.data = {
      "0": [{
        "question": "How often is real property re-assessed (or revalued)?",
        "id": 1,
        "section": "Assessment",
        "sectionId": 2,
        "check": true,
        "index": 0
      }, {
        "question": "How often is real property re-assessed (or revalued)?",
        "id": 2,
        "section": "Assessment",
        "sectionId": 2,
        "check": true,
        "index": 0
      }, {
        "key": "Survey Meta Data"
      }],
      "1": [{
        "question": "When are New Assessment Notices sent out?",
        "id": 2,
        "section": "Assessment",
        "sectionId": 2,
        "check": true,
        "index": 1
      }, {
        "key": "Assessment"
      }]
    };
  });

This will print out as you want.

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.