I've been searching on various forums for an answer to my AngularJS issue without any luck. I have a simple controller that calls an http service and reads the response data, which is in JSON format with an objects array. However, I'm facing difficulty accessing the 'results' array.
Here's the structure of the JSON output:
{
"results": [{
"id": "1",
"download_url": "",
"uploader": {
"id": "114899"
},
"uploaded": "1442599380",
"streaming_url_timeout": 1446092554
}, {
"id": "2",
"download_url": "",
"uploader": {
"id": "114899"
},
"uploaded": "1442599380",
"streaming_url_timeout": 1446092554
}]
}
In my Service method that retrieves this JSON data:
this.getUData = function() {
var deferred = $q.defer();
$http.jsonp(API_URL + 'udata')
.success(function(data) {
deferred.resolve(data);
})
.error(function(data) {
deferred.reject(data);
});
return deferred.promise;
}
This is how I invoke the service from my controller:
myservices.getUData().then(function(data) {
$scope.uitems = data.results;
});
In the template:
<div class="item" href="#" ng-repeat="item in uitems">
<h2>{{item.id}}</h2>
</div>
However, upon trying to access the items in 'results', I encounter the following error:
Uncaught SyntaxError: Unexpected token :
The error seems to be originating from the line "results":[
.