i have query regarding passing param objects to $resource get method.
in the backend restful application i am not getting the routeparam values passed . here my sample code
on clicking the search button from the html page it is moving to controller as mentioned in myapp.js
myapp.js var app = angular.module('myApp', [ 'MyServices']);
app.config([ '$routeProvider', function($routeProvider) {
$routeProvider
.when('/employeesearch/:empID/:deptID', {
templateUrl : 'partials/result.html',
controller : SearchController
})
.otherwise({
redirectTo : '/defaultsearch'
});} ]);
on doing console.log in controller.js file , the routeparams values are displayed correctly
SearchController.js
function SearchController($scope, $routeParams, EmployeeSearch) $scope.mydata = EmployeeSearch.getSearchResult($routeParams.empID,$routeParams.deptID);
}
myservices.js
angular.module('MyServices', ['ngResource']).
factory('EmployeeSearch', function($resource){
return $resource('rest/employees/:eID/:dID', {}, {
query: {method:'GET', params:{}, isArray:false},
getSearchResult:{method:'GET', params:{eID:'empID',dID:'deptID'}}
});
});
backend restful java class
@Path("/employees") public class EmployeeSearchService {
@Path("{eID}/{dID}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Employee searchmethod(@PathParam("eID") String empId, @PathParam("dID") String deptId) {
System.out.println("eid:"+empId);
System.out.println("did:"+deptId);
return new Employee(); }
on hitting the restful url :http:localhost:9080/MyProject/rest/employees/e12/d12
- the value of eid is 'e12' and did is "d12"
but on hitting via the anugular it is displaying the value of eid as "empID" and did as "deptID",
it is displaying the value as i mentioned in the myservices.js file
Can you please help me out in this? what am i giving wrongly?
Reference site: https://github.com/teunh/jfall2012/blob/master/demo/web/index.html