Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display data from json with ng-repeat

Tags:

json

angularjs

So i loaded the json and now i cant display it and it says 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"
}
like image 455
Branka Avatar asked Dec 07 '25 02:12

Branka


1 Answers

Try like this

<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>
like image 199
Anik Islam Abhi Avatar answered Dec 08 '25 18:12

Anik Islam Abhi