Previously I was passing url by some services in angular js. Now I want to pass url to $resource from controller as a parameter.
I have tried to pass url to resource from controller but it throwing error that url object not found.
Following is my current factory code:
angular.module('Services').factory('PatientsService', ['$resource', 'Service', '$http',
function(Resource, Service, Http) {
return {
testGetPatients : Resource(Service.getPatientsCustomRefURL(), {}, {
query : {
method : 'GET',
isArray : false
}
})
};
}]);
In above code I am sending url parameter from Service.getPatientCUstomRefURL
Actual call to $resource is shown below:
PatientsService.getPatientsRef.query(function(refResponse) {
//TODO for response
});
Now I want to pass Parameter something like this:
PatientsService.getPatientsRef.query("/patient/list",function(refResponse) {
//TODO for response
});
What changes should I make in my PatientsService factory so that it will support passing url as parameter.
Here is code which will create url for $resource Services code
angular.module('Services', ['ngResource']).factory('Service', ['$resource', '$location', '$rootScope',
function($resource, $location, $rootScope) {
return {
getPatientsCustomRefURL: function() {
return '/patient/list';
}
};
}
]);
Note
I have so many methods in PatientService, so i dont want to add extra function in patientService for each $resource, which will pass url as parameter like
angular.module('Services').factory('PatientsService', ['$resource', 'Service', '$http',
function(Resource, Service, Http) {
return {
testGetPatients : function(url){
return Resource(url, {}, {
query : {
method : 'GET',
isArray : false
}
})
}
};
}]);