I'm trying to display a list of elements by name and id with ng-repeat
from a json with a super simple ajax request.
var form = $("#loadAllServiceEngineForm");
var url = form.attr("action");
var App = angular.module('AdamApp', []);
App.controller('locContol', function($scope, $http) {
// Simple GET request
$http.get(url).
success(function(data) {
$scope.locations = angular.fromJson(data);
console.log(data);
}).
error(function(data) {
console.error("NON CARICA I DATI");
});
});
In this list
<body ng-app="AdamApp">
<div ng-controller="locContol">
<ul>
<li ng-repeat="location in locations | orderBy: 'id'">
<div>{{location.name}}-{{location.id}}</div>
</li>
</ul>
</div>
</body>
The strange thing is which it return a list of empty <li>
, and in console i see the strange Array attached.
And this is the full json in console.log.
I don't know angular, i'm just trying for the first time... but i see the difference between jQuery
ie. when i call the same json
with $.ajax
and then parse with JSON.parse(data[i]);
it display in console an ordinate list of objects instead this strange array of objects.
How i can get a same result in angular?
.then
method while will give you the response data available and you wont need to do any json parsing.$scope.locations = angular.fromJson(data);
. then check your consolejson
inconsole
.