javascript - AngularJS: Unable to see data from REST -


i'm working on web app , using angularjs display set of locations rest api onto template, need display on template. how list of rest data show on html template?

index.html:

 <!doctype html> <html ng-app="countryapp">   <head>   <title>angular app</title>   <script src="js/angular.min.js"></script>   <script src="js/angular-route.min.js"></script>   <script src="js/app.js"></script>   </head>    <body>     <!--stuff-->      <div ng-view=""></div>      <!--end stuff-->    </body> </html>    

view/all_locations.html

<div ng-controller="alllocations">      <h3>hello</h3>      <ul><li ng-repeat="location in locations"><p>{{locations.location_id}}<p></p></li><ul> 

app.js file

//app.js var countryapp = angular.module('countryapp', ['ngroute']);       countryapp.config(function($routeprovider) {         $routeprovider.             when('/', {              templateurl: 'views/all_locations.html',              controller: 'alllocations'            }).            when('/:location_id', {                templateurl: 'views/view_location.html',               controller: 'viewlocation'            }).            otherwise({              redirectto: '/'            });         });       countryapp.controller('alllocations', function ($scope, $http){         $http.get('http://localhost/slimtest2/locations').success(function(data) {               $scope.locations = data;             });         });       countryapp.controller('viewlocation', function ($scope, $routeparams){         console.log($routeparams);       }); 

json data rest api

{ "locations" :[{"location_id":"2","location_reference":"657821349","location_title":"guam premier outlet,? ???? ???"},{"location_id":"3","location_reference":"5328016947","location_title":"underwater world,?? ?? ??"},{"location_id":"4","location_reference":"8476039215","location_title":"fort santa agueda,?? ?? agueda"},{"location_id":"5","location_reference":"5320468719","location_title":"dulce nombre de maria cathedral,dulce? nombre ? ??? ???"},{"location_id":"6","location_reference":"8530697412","location_title":"leo palace resort,?? ??? ???"},{"location_id":"7","location_reference":"5309187462","location_title":"fort soledad,?? ?? ??"}]} 

try changing

ng-repeat="location in locations" 

to

ng-repeat="location in locations.locations" 

and

{{locations.location_id}} 

to

{{location.location_id}} 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -