Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  152] [ 4]  / answers: 1 / hits: 7008  / 10 Years ago, mon, june 9, 2014, 12:00:00

I am passing three parameters from my controller to the factory following way.



In my controller I am trying to pass three parameters id,sdt and edt ..



 $scope.val = function () {
$scope.tech = techRepository.getTech.query({ id: $scope.id, sdt: $scope.sDate, edt: $scope.eDate }, function(data) {
scope.tech = data;
});
};


In my factory I have



App.factory('techRepository', ['$resource', function ($resource) {
return {
getTech: $resource('/api/Tech/GetRange/:id', {id: '@id', start: '@sdt', end: '@edt'}, {query: {method: 'GET', isArray:true}})
};
}]);


When I run this I get Bad Request error. Please let me know how to pass multiple parameters. Thanks


More From » angularjs

 Answers
17

This works fine, presuming you want :id in your query string to be replaced with the value of $scope.id, and two query parameters (sdt and edt) attached like:



http://www.example.com/api/Tech/GetRange/123?edt=20140610&sdt=20140609


It seems like you may instead be expecting a URL that looks like:



http://www.example.com/api/Tech/GetRange/123?end=20140610&start=20140609


... in which case, your code should look like:



// in controller
$scope.val = function () {
$scope.tech = techRepository.getTech.query({ id: $scope.id, start: $scope.sDate, end: $scope.eDate }, function(data) {
scope.tech = data;
});
};

.factory('techRepository', ['$resource', function ($resource) {
return {
getTech: $resource('/:id', {id: '@id'}, {query: {method: 'GET', isArray:true}})
};
}]);


Demo


[#44712] Friday, June 6, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shylaelisan

Total Points: 37
Total Questions: 94
Total Answers: 110

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;