How to display data from json with ng-repeat

So I downloaded the json and now I cannot display it and it says it is not well formed. But I'm not really sure what to write in html.

here is my js:

app.controller('jsonController', function($scope, $http) {
    $http.get('podaci.json').success(function(data) {
        $scope.gradovi = data;
    });
});

      

and html:

<div ng-controller = "jsonController">
   <ol>
      <li ng-repeat="gradovi in ponudjene">
         {{gradovi.ponudjene}}
      </li>
   </ol>
</div>

      

and this is json:

{
   "ponudjene": [
      "Ada",
      "Adaševci",
      "Žitni Potok",
      "Žitorađa",
      "Zlatibor",
      "Zlatica",
      "Zlodol",
      "Zlot",
      "Zmajevo",
      "Zminjak",
      "Zrenjanin",
      "Zubin Potok",
      "Žuč",
      "Zuce",
      "Zvečan",
      "Zvezdan",
      "Zvonce",
      "Đala",
      "Đunis",
      "Đurđevo",
      "Đurđin"
   ],
   "tacno": [
      "Zvezdan",
      "Zvezdan",
      "Bor",
      "Rudna Glava",
      "Majdanpek"
   ],
   "vreme": 100,
   "oblast": "Istocna srbija"
}

      

+3


source to share


3 answers


try it



<ol>
   <li ng-repeat="item in gradovi.ponudjene">
      {{item}}
   </li>
   <li ng-repeat="item in gradovi.tacno">
      {{item}}
   </li>
   <li>
      {{gradovi.vreme}}
   </li>
   <li>
      {{gradovi.oblast}}
   </li>
</ol>

      

+2


source


Not sure what your json data looks like, but your $ scope is "gradovi", so your li should look something like this:

<li ng-repeat="item in gradovi">
     {{item.name_of_field_in_your_json}}
</li>

      

UPDATE:



Now that I can see your json data. Here is the violin:

http://jsfiddle.net/RkykR/778/

0


source


Find him! Thanks everyone for the help! :)

<ol>
<li ng-repeat="item in gradovi.ponudjene track by $index">
 {{item}}
</li>
</ol>

      

0


source







All Articles