0

I need to get all the documents from PouchDB database and store them in $scope variable (AngularJS). Can anyone tell me how to get the 'doc' from the callback function?

db.allDocs({include_docs: true, descending: true}, function(err, doc) {
    $scope.info = doc;

});

Outside of this code, $scope.info is undefined, the doc object is not stored in this variable

1 Answers1

1

I assume that the db is a 3rd party code not part of angularjs or a service, then you need to do it like

db.allDocs({include_docs: true, descending: true}, function(err, doc) {
  $scope.$apply(function(){  
    $scope.info = doc;
  })
});

because angularjs is not aware of changes that happens somewhere else

maurycy
  • 8,455
  • 1
  • 27
  • 44