Skip to content

Instantly share code, notes, and snippets.

@kranack
Created January 15, 2016 16:10
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 kranack/6c8769a8b18c62d9d653 to your computer and use it in GitHub Desktop.
Save kranack/6c8769a8b18c62d9d653 to your computer and use it in GitHub Desktop.
Home Controller
'use strict';
var homeController = angular.module('homeController', ['ionic', 'pouchdb']);
homeController.controller('homeCtrl', ['$scope', 'pouchBindingSimple', 'pouchCollection',
function($scope, pouchBindingSimple, pouchCollection) {
$scope.books = pouchCollection('books');
$scope.userInfo = {
firstName: 'Jo', lastName: 'Bloggs'
};
pouchBindingSimple('user-info', $scope, 'userInfo');
$scope.online = false;
$scope.toggleOnline = function() {
$scope.online = !$scope.online;
if ($scope.online) { // Read http://pouchdb.com/api.html#sync
$scope.sync = $scope.books.$db.replicate.sync('http://localhost:5984/books', {live: true})
.on('complete', function (info) {
console.log(info);
console.log($scope.books);
})
.on('error', function (err) {
console.log("Syncing stopped");
$scope.online = false;
console.log(err);
});
} else {
$scope.sync.cancel();
}
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment