Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

angularjs controller

controller('FaqCtrl', function($scope, $http)
{
$http.get("api/index.php/faq/getqusans")
.success(function (response) {
$scope.name = response.catname;

$scope.records = response.catname;

//$scope.question = response.records;

}); 
}).

HTML Code

<div ng-controller="FaqCtrl" class="row">
<div class="" ng-repeat="y in name">
    <h3>{{ y.name }}</h3><br/>
    <div class="col-md-6" ng-repeat="x in records">

        <accordion close-others="true" >
            <accordion-group is-open="status1.open" ng-class="{'expanded': status1.open}" >
                <accordion-heading>{{ x.question }}</accordion-heading>
                {{ x.answer }}
            </accordion-group>

        </accordion>

    </div>
</div>

Json response

{
              "catname": [
                {
                  "name": "How do i 2",
                  "records": [
                    {
                      "question": "propose a new dish",
                      "answer": "Anim "
                    }
                  ]
                },
                {
                  "name": "How do i 3h",
                  "records": [
                    {
                      "question": "supply the dishes being demanded by heartyy",
                      "answer": "Anim"
                    },
                    {
                      "question": "sdsffd",
                      "answer": "vcvcvcvcvcv"
                    }
                  ]
                }
              ]
            }

I am not gat the question and answer print in html. only print the name is like 'How do i 2' and 'How do i 2' but name have the quection 'propose a new dish' and answer 'Anim'.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

We need to write html as below

JSFIDDLE

HTML CODE

  <div ng-app ng-controller="LoginController">
 <div class="col-md-6" ng-repeat="x in parsedData">
<accordion close-others="true">
    <accordion-group is-open="status1.open" ng-class="{'expanded': status1.open}">
        <div>{{ x.name }}</div>
        <div ng-repeat="y in x.records">
            <accordion-heading><p>question is{{ y.question }}</p></accordion-heading>

JS CODE

function LoginController($scope) {
    var dataArr =[];
    var dataJson = {};
    $scope.data = {
              "catname": [
                {
                  "name": "How do i 2",
                  "records": [
                    {
                      "question": "propose a new dish",
                      "answer": "Anim "
                    },
                      {
                      "question": "propose a new dish",
                      "answer": "Anim "
                    },
                      {
                      "question": "propose a new dish",
                      "answer": "Anim "
                    }
                  ]
                },
                {
                  "name": "How do i 3h",
                  "records": [
                    {
                      "question": "supply the dishes being demanded by heartyy",
                      "answer": "Anim"
                    },
                    {
                      "question": "sdsffd",
                      "answer": "vcvcvcvcvcv"
                    }
                  ]
                }
              ]
            };

    $scope.parsedData = $scope.data.catname;
    console.log($scope.parsedData);
};

o/p:

How do i 2
question ispropose a new dish

answer is Anim

question ispropose a new dish

answer is Anim

question ispropose a new dish

answer is Anim

How do i 3h
question issupply the dishes being demanded by heartyy

answer is Anim

question issdsffd

answer is vcvcvcvcvcv

JSFIDDLE

share|improve this answer
    
Thsi is print only last 2 question. I want to output is like – sachin saini Jun 23 at 6:37
    
There are only two question in the json. can you please elaborate your requirement so i can better explain the solution – PavanAsTechie Jun 23 at 6:40
    
Do you want this jsfiddle.net/pavanastechie/Lt7aP/645 – PavanAsTechie Jun 23 at 6:51
    
@sachin I got you here is the desired answer. if you like give one up vote – PavanAsTechie Jun 23 at 6:53
    
This is print only last 2 question. I want to output is like name: How do i 2 question: propose a new dish answer: Anim name: How do i 3h question: supply the dishes being demanded by heartyy answer: Anim question: sdsffd answer: vcvcvcvcvcv – sachin saini Jun 23 at 6:55

Try this:

<div class="col-md-6" ng-repeat="x in catname">
    <accordion close-others="true">
        <accordion-group is-open="status1.open" ng-class="{'expanded': status1.open}">
            <accordion-heading>{{ x.records.question }}</accordion-heading>
            {{ x.records.answer }}
        </accordion-group>
    </accordion>  
</div>
share|improve this answer
    
This code is not work same problam. – sachin saini Jun 23 at 5:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.