我有關於傳遞param對象到$ resource get方法的查詢。
在後端restful應用程序我沒有得到傳遞的routeparam值。 這裏從它移動到控制器如myapp.js
myapp.js 變種應用= angular.module(「對myApp」提到的html頁面點擊搜索按鈕我的示例代碼
,[' MyServices']);
的app.config([ '$ routeProvider',函數($ routeProvider){
$routeProvider
.when('/employeesearch/:empID/:deptID', {
templateUrl : 'partials/result.html',
controller : SearchController
})
.otherwise({
redirectTo : '/defaultsearch'
});} ]);
在controller.js文件做的console.log,正確
SearchController顯示routeparams值。 JS
功能SearchController($範圍,$ 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'}}
});
});
後端寧靜的Java類
@Path( 「/僱員」) 公共類EmployeeSearchService {
@Path( 「{電子身份證}/{} DID」)
@ GET
@Produces(MediaType.APPLICATION_JSON)
公務員searchmethod(@PathParam( 「電子身份證」)字符串EMPID,@PathParam( 「爲什麼」)字符串DEPTID){
System.out.println("eid:"+empId);
System.out.println("did:"+deptId);
return new Employee(); }
在碰到寧靜的URL:http:本地主機:9080/MyProject的/ REST /員工/ E12/D12
- EID的值是「E12」,並沒有爲「D12」
但通過anugular 它顯示EID爲「EMPID」的價值,並沒有爲「DEPTID」打,
它顯示的值正如我在myservices.js文件中提到的
你能幫我解決嗎?我給錯了什麼?
參考網站:https://github.com/teunh/jfall2012/blob/master/demo/web/index.html
你傳入字符串值「EMPID」和「DEPTID」在這一行的名字'getSearchResult:{方法:'GET',params:{eID:'empID',dID:'deptID'}}'。 –
但empID和deptID是app.js中的routeparams名稱,所以我認爲它應該從url中獲取值。對不起,我剛開始學習角js。那麼我應該如何將價值傳遞給安寧的服務呢? – user2495903
params是默認值,你可以將你的調用中的值傳遞給getSearchResult,而不是'EmployeeSearch.getSearchResult({eID:$ routeParams.empID,dID:$ routeParams.deptID});' –