user2882684 user2882684 - 4 months ago 15
AngularJS Question

push json get request items into an array

I'm trying to push json objects into an array with angular. I'm getting an error 'Cannot read property 'push' of undefined'. Is there another way to do this with angular?

$.each(data.Document.Placemark, function(index, item) {
var locations = [];
$scope.locations.push(item.name + ", " + item.Point.coordinates);
});

Answer

If you want locations to be a property of $scope then you have to make it a property of $scope instead of a local variable.

$scope.locations = [];
Comments