AngularJS Todo with PouchDB backend

This is the AngularJS Todo example with a PouchDB backend. Here's the original example: http://jsfiddle.net/dakra/U3pVM/

by yoorek

HTML

<script src="http://download.pouchdb.com/pouchdb-nightly.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<h2>Todo</h2>

<div ng-controller="MainCtrl"> <div class="label label-primary">{{remaining()}} of {{todos.length}} remaining</div>
[ <a href="" ng-click="removeDone()">Remove done</a> ]
    <ul class="unstyled">
        <li ng-repeat="todo in todos">
            <input type="checkbox" ng-model="todo.done" ng-click="updateTodo(todo)" /> <span ng-class="{done:todo.done}">{{todo.text}}</span>

        </li>
    </ul>
    <form class="form-horizontal" ng-submit="addTodo()">
        <input class="form-control" type="text" ng-model="todoText" size="30" placeholder="add new todo here" />
        <input class="btn btn-primary form-control" type="submit" value="add" />
    </form>
</div>

CSS

.done {
    text-decoration: line-through;
    color: grey;
    font-style: italic;
}

JavaScript

function MainCtrl($scope) {

    $scope.todos = [];

    $scope.pouchdb = PouchDB('angularpouchtodo', function (err, db) {
        if (err) {
            console.log(err);
        } else {
            db.allDocs(function (err, response) {
                if (err) {
                    console.log(err);
                } else {
                    $scope.loadTodos(response.rows);
                }
            });
        }
    });

    $scope.loadTodos = function (todos) {
        for (var i = 0; i < todos.length - 1; i++) {
            var todo = todos[i];
            $scope.pouchdb.get(todo.id, function (err, doc) {
                if (err) {
                    console.log(err);
                } else {
                    $scope.$apply(function () {
                        $scope.todos.push(doc);
                    });
                }
            });
        };
    }

    $scope.addTodo = function () {
        var newTodo = {
            text: $scope.todoText,
            done: false
        };
        $scope.todos.push(newTodo);
        $scope.todoText = '';
        $scope.pouchdb.post(newTodo);
    };

    $scope.updateTodo = function (todo) {
        $scope.pouchdb.put(todo);
    };

    $scope.remaining = function () {
        var count = 0;
        angular.forEach($scope.todos, function (todo) {
            count += todo.done ? 0 : 1;
        });
        return count;
    };

    $scope.removeDone = function () {
        var oldTodos = $scope.todos;
        $scope.todos = [];
        angular.forEach(oldTodos, function (todo) {
            if (!todo.done) {
                $scope.todos.push(todo);
            } else {
                $scope.removeTodo(todo);
            }
        });
    };

    $scope.removeTodo = function (todo) {
        $scope.pouchdb.get(todo._id, function (err, doc) {
            if (err) {
                console.log(err);
            } else {
                $scope.pouchdb.remove(doc, function (err, response) {
                 ...