Skip to content

Instantly share code, notes, and snippets.

@tlvince
Created September 12, 2014 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlvince/be2ec108df073040f8b0 to your computer and use it in GitHub Desktop.
Save tlvince/be2ec108df073040f8b0 to your computer and use it in GitHub Desktop.
angular-pouchdb example
<html ng-app="app">
<body>
<div ng-controller="AppCtrl">
<button ng-click="add()">Add</button>
<ul>
<li ng-repeat="doc in docs">
<span ng-bind="doc|json"></span>
</li>
</ul>
</div>
<script src="https://code.angularjs.org/1.2.22/angular.js"></script>
<script src="https://cdn.jsdelivr.net/pouchdb/2.2.3/pouchdb.js"></script>
<script src="https://rawgit.com/angular-pouchdb/angular-pouchdb/master/angular-pouchdb.js"></script>
<script>
angular.module('app', ['pouchdb'])
.controller('AppCtrl', function($scope, PouchDB) {
var db = new PouchDB('news');
$scope.docs = [];
$scope.add = function add() {
db.post({date: new Date().toJSON()})
.then(function(res) {
console.log(res);
});
}
function onChange(change) {
$scope.docs.push(change.doc);
}
db.changes({
include_docs: true,
continuous: true,
onChange: onChange
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment