I am trying to load the pouchdb client database on start of the application from within a javascript file but the database does not get created. There are no console errors in the debugger. When I try to debug, it seems to fail on this line below because it exits the anonymous function and does not allow me to step into the function further.
fails here--> angular.module('app').factory(serviceId, [ 'pouchdb', createclientdb]);
Any idea why I may be doing wrong?
(function () {
'use strict';
var serviceId = 'clientedb';
angular.module('app').factory(serviceId, [ 'pouchdb', createclientdb]);
function createclientdb(pouchdb) {
return pouchdb.create('mydb', function callback(err, result) {
if (!err) {
alert('Successfully added a program!');
}
else {
alert('Failed added a program!');
}
});
return true;
}
});
Latest error generate uncaught exception.
(function () {
'use strict';
var databasename = 'mydb';
angular.module('app.clientdb', [])
.factory('clientdb', ['pouchdb', function (pouchdb) {
return pouchdb.create(databasename, function callback(err, result) {
if (!err) {
alert('Successfully added a program!');
}
else {
alert('Failed added a program!');
}
});
}]);
});
I also have the following service. Any suggestions?
(function () {
'use strict';
angular.module('app').factory('clientdbservice', ['pouchdb','app.clientdb',clientdbservice]);
function clientdbservice(clientdb) {
return {
adddata: function (obj) {
clientdb.put(obj)
.then(function () {
log('data added to Client DB');
})
.catch(function (error) {
log('Could not add data to Client DB');
}).finally(function () {
// Do something when everything is done
});
}
};
};
});