2

I am trying to print some data from a JSON end point using AngularJS. End point :- http://localhost:8081/api

JSON structure :-

{
  "1": {
    "venture": "XYZ Informatics",
    "member": [
      {
        "name": "abcd",
        "email": "[email protected]"
      }
    ],
    "message": "This is good day",
    "isclicked": false
  },
  "2": {
    "venture": "BBC Informatics",
    "member": [
      {
        "name": "xyz",
        "email": "[email protected]"
      }
    ],
    "message": "This is bad day",
    "isclicked": false
  }
}

I want to display the name of venture s in row. My expected output in row is :-

XYZ Informatics
BBC Informatics

My Code is :-

    <!DOCTYPE html>
<html ng-app="MyApp">
  <head>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
    <style>
      table, th, td {
      border: 1px solid black;
      border-collapse: collapse;
      }
      th, td {
      padding: 15px;
      }
    </style>
  </head>
  <body>
    <div ng-app="MyApp" ng-controller="displayController">
      <table style="width:100%">
        <tr ng-repeat="data in datas">
          <td>{{ data.venture }}</td>
        </tr>
      </table>
    </div>
    <script>
      angular.module('MyApp', [])
      .controller('displayController', function($scope, $http) {
      var url = "http://localhost:8081/api";
      $http.get(url).success(function (response) {
      $scope.datas = response;
      });
      }
    </script>
  </body>
</html>

But the value is not displaying. Probably, I am missing to get into each array of JSON.

0

1 Answer 1

5

There is a syntax error on your script. Close the brackets for your controller.

  <script>
    angular.module('MyApp', [])
      .controller('displayController', function($scope, $http) {
        //changed to your local api
         var url = "http://localhost:8081/api";
        $http.get(url).success(function(response) {
          $scope.datas = response;
        });
      });//this is the place where you miss out the closing bracket
  </script>

Here is the working plnkr.

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

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.