Is it possible to add virtual attributes to a ngResource? I created a service like this
app.factory('Person', ['$resource', function($resource) {
return $resource('api/path/:personId', {
personId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}])
Person
has an attribute name
and an attribute surname
.
I want to retrive the fullname
by adding a virtual attribute fullname
returning resource.name + resource surname
.
I know I could add it in the controller, but adding it to the service it will make it much more portable.
I tried something like this
app.factory('Person', ['$resource', function($resource) {
return $resource('api/path/:personId', {
personId: '@_id'
}, {
update: {
method: 'PUT'
},
fullname: function(resource){
return resource.name + ' ' + resource.surname;
}
});
});
}])
but it doesn't work.