简体   繁体   中英

Get data from PouchDB callback function?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM