Currently, the url localhost/view/titles
is set up to use the specific route, controller, and service described below. When accessed, the server will return a list of all title objects. How can the service be expanded to accommodate additional query parameters, such as a result limit?
// AngularJS app module with route configuration
var app = angular.module('app', ['ngResource']).
config(function ($routeProvider, $locationProvider) {
$routeProvider.when(
'/view/:obj/:limit',
{
templateUrl: '/static/templates/titles.html',
controller: 'titlesController'
}
)})
// List service definition
var listService = app.factory('listService', function ($q, $resource) {
return {
getList: function (obj) {
var deferred = $q.defer();
$resource('/api/view/' + obj).query(
function (response) {
console.log('Request successful')
deferred.resolve(response);
},
function (response) {
console.log('Request failed with status: ' + response.status)
deferred.reject(response);
}
)
return deferred.promise;
}
}
}
)
// Controller definition
var titlesController = bang.controller('titlesController', function($scope, listService, $routeParams){
$scope.titles = listService.getList($routeParams.obj);
})