Created
September 12, 2014 22:24
-
-
Save tlvince/be2ec108df073040f8b0 to your computer and use it in GitHub Desktop.
angular-pouchdb example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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