0

I am newbie to AngularJS. I have JSON file which I have to fetch using angularjs!

JSON File

{
  "records": [
    {
      "students": [
        {
          "id": 1,
          "name": "Bill",
        },
        {
          "id": 2,
          "name": "Steve",
        }
        ],
      "exstudent": [
        {
          "id": 1,
          "name": "Woz",
        },
        {
          "id": 2,
          "name": "Jonathan",
        }
        ]
    }
    ]
}

Controller part snippet -

 $http.get('json/somedata.json').success(function (data){

        $scope.name = data.records.student.name;
        $scope.exname = data.records.exstudent.name;

        });


  }])

HTML

<div class="panel-body" ng-repeat = "browse in name">
  {{browse.student.name}}
</div>

Which part I am doing wrong? I think the problem is with ng-repeat! Need Help

0

1 Answer 1

2

You can't use data.records.students.name as students is an Array.

You can however store its data into your $scope and use it in the ng-repeat:

$http.get('json/config.json').success(function (data){
    $scope.students = data.records.students;
    $scope.exstudents = data.records.exstudent;
});

Then in your HTML use the ng-repeat like this:

<div class="panel-body" ng-repeat="student in students">
    {{student.name}}
</div>
Sign up to request clarification or add additional context in comments.

Comments