Angular: tiene múltiples funciones en un servicio
¿Es posible tener múltiples funciones en un solo servicio?
Tengo esto en mi servicio de libros:
(function() {
'use strict';
angular
.module('app.core')
.service('BookService', BookService);
BookService.$inject = ['$resource'];
/* @ngInject */
function BookService($resource) {
return $resource('/api/book/:id', {
id: '@id'
}, {
'get': {
method: 'GET',
cache: true
},
'query': {
method: 'GET',
isArray: true,
cache: true
},
});
}
})()
Pero en el mismo servicio quiero tener otra función donde pasaré otros parámetros, por ejemplo:
return $resource('/api/book/:name', {
name: '@name'
}, {
'get': {
method: 'GET',
cache: true
},
'query': {
method: 'GET',
isArray: true,
cache: true
},
});
Mi controlador se ve así y tiene dos llamadas diferentes:
BookService.get({
id: 2
}, function(book) {})
BookService.get({
name: "bookTitle"
}, function(book) {})