Marcello Nuccio
unread,Nov 11, 2011, 11:31:38 AM11/11/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ang...@googlegroups.com
Sure, but be warned: I'm a Javascript and AngularJS newbie...
// Setup the $xhr.error service to alert() errors.
// Change it to fit your application!
angular.service('$xhr.error', function () {
return function (request, response) {
var msg, body;
if (response) {
body = response.body;
msg = 'ERROR ' + response.status + ': ' + (typeof body !== 'string' ? JSON.stringify(body) : body);
} else {
msg = 'REQUEST FAILED: ' + JSON.stringify(request);
}
alert(msg);
};
}, { $eager: true });
// Service for getting documents:
angular.service('Document', function ($resource) {
return $resource('/db/:id', { id: '@_id' }, {
query: {
method: 'GET',
isArray: false,
params: {
id: '_all_docs',
include_docs: 'true'
}
},
save: { method: 'PUT' }
});
}, { $inject: ['$resource'] });
Then you can get a document with:
var doc = Document.get({ id: 'DOCID' });
You can save it with any of:
doc.$save();
Document.save(doc);
Hope it helps,
Marcello