Is it possible to have multiple functions in one service?
I have this in my book:
(function() { 'use strict'; angular .module('app.core') .service('BookService', BookService); BookService.$inject = ['$resource']; function BookService($resource) { return $resource('/api/book/:id', { id: '@id' }, { 'get': { method: 'GET', cache: true }, 'query': { method: 'GET', isArray: true, cache: true }, }); } })()
But in the same service, I want to have another function, where I will pass other parameters, for example:
return $resource('/api/book/:name', { name: '@name' }, { 'get': { method: 'GET', cache: true }, 'query': { method: 'GET', isArray: true, cache: true }, });
My controller looks like this and has two different calls:
BookService.get({ id: 2 }, function(book) {}) BookService.get({ name: "bookTitle" }, function(book) {})
source share