In the code below, I'd like the $scope.persons variable to consist of an array of objects that I GET from CouchDB.
.controller('personsCtrl', ['$scope', 'personSrv', function personsCtrl($scope, $http) {
$scope.persons = function(){
return $http.get('http://localhost:5984/quotes/_all_docs?include_docs=true')
.then(function(response) {
if (typeof response.data === 'object') {
return $.map(response.data, function(el){return el});
} else {
// invalid response
return $q.reject(response.data);
}
}, function(response) {
// something went wrong
return $q.reject(response.data);
});
}
}])
So that I can display the information on my page like this:
<div>
<p class="lead">Persons</p>
<ul>
<li ng-repeat="p in persons"><a ng-href="#/quotes/{{ p.doc.dataid }}">{{ p.doc.dataname }}</a></li>
</ul>
</div>
Each object/person has an id, a name and a quote. I tried using $.map to convert the data I got from the GET to an array, but it doesn't seem to work...
$scope.persons.push(response.data)