0
我仍然在學習角度,並試圖與json一起使用post方法。繼承人的JSON的樣子與REST的角度http發佈
[{"race":{"date":"Thu 6th Apr", "raceName" :"final race" ,"horses":[{"horse":{"age":"9yo" "horseName":"The New One"Davies", {"distanceWins":0,"horse":{ "age":"9yo" "horseName":"Buveur D'Air" , {"distanceWins":0,
我能夠得到使用角控制器連接到一個html頁面種族所看到如下
angular.module('horseApp.RacesController',[]).
controller('RacesController', function ($scope, $stateParams, $http, $state){
$http.get('restful-services/api/getAllRaces')
.success(function(data, status) {
$scope.race = data;
})
.error(function (error) {
alert('An error occurred');
});
<table>
<tr>
<th>Race</th>
<th>Date</th>
</tr>
<tr ng-repeat="r in race" ng-click="showRace(r)">
<td>{{r.race.raceName}}</td>
<td>{{r.race.date}}</td>
</tr>
</table>
我想要做的是,當某人點擊一場比賽,它將顯示一個新的HTML頁面,並與該比賽中的所有馬匹進行比較。這是我試過的。在這種控制器,在i貼上面我說這個方法
$scope.showRace = function (race) {
console.log(race.horse,'HORSES');
$state.go('specificRace',{
horse:race.horse
})
}
在一個新的控制器,我加入這個帖子方法與HTML這是顯示馬比賽被點擊
angular.module('horseApp.ProfileController',[]).
controller('ProfileController', function ($scope, $stateParams, $http) {
var horsename = $stateParams.horsename;
console.log(horsename);
$http.post('restful-services/horse/getHorseByHorsename', horsename)
.success(function(data, status) {
$scope.horse = data;
})
.error(function (error) {
alert(error);
});
});
<table>
<tr>
<th>Horse Name</th>
</tr>
<tr>
<td>{{race.horse.horseName}}</td>
</tr>
</table>
目前我當「M在ProfileController可和500()錯誤交http://localhost:8080/restful-services/horse/getHorseByHorsename從我RESTAPI類及彼第6行未定義錯誤
@POST
@Path(value="/getHorseByHorseName")
@Produces(value={"application/json"})
public Horse getHorseByHorseName(String horsename) {
return horseDAO.findByHorsename(horsename);
}
對不起的長度張貼,任何幫助非常感謝。
發送到服務器的數據需要一個鍵/值對...所有您發送的是值 – charlietfl