This question already has an answer here:
- Angular - extending $resource subobject with custom methods 4 answers
I have an angular resource that goes something like this
app.factory('User', function ($resource) {
return $resource(
'/api/user/:listCtrl:id/:docCtrl/', {
id: '@id',
listCtrl: '@listCtrl',
docCtrl: '@docCtrl'
}, {
update: {
method: 'PUT'
},
current: {
method: 'GET',
params: {
listCtrl: 'current'
}
},
nearby: {
method: 'GET',
params: {
docCtrl: 'nearby'
},
isArray: true
}
}
);
});
now i want to have full name in the view, can i add a method so that when i do this
$scope.user = User().current();
instead of doing the following in html
<p>{{ user.first_name }} {{ user.last_name }}</p>
i do this
<p>{{ user.get_full_name }}</p>
is there a way to add this property to the $resource
?