我创建了一个 angular-promise,它调用一个 http 方法(对应于一个休息服务),它应该在提交表单时调用,使用 ng-submit。它永远不会发生,也没有错误,似乎从未调用过该函数。所以这里是javascript代码:
myapp.factory('CardFactory', ['$http', function($http){
return{
cardService: function(hclass) {
return $http({
method: 'get',
url: UrlServices.baseUrl + 'http://localhost:8080//HSRestServices/hsrest/decks/getCards/' + hclass,
})
}
}
}])
myapp.controller('CardCtrl', ['$scope', 'CardFactory', function($scope, CardFactory ){
$scope.card = "Druid";
$scope.cardService = function() {
CardFactory.cardService($scope.card)
.then(function (response) {
$scope.status = response.status;
$scope.card = response.data;
console.log("Response: " + JSON.stringify({data: response.data}));
if (response.status == 200){
$scope.card = response.data;
} else {
console.log("Response: Something went wrong.");
}
}, function (response) {
console.log("Response: Something went wrong.");
})
};
}]);
和html代码:
<body ng-app="mainApp">
<div ng-controller="CardCtrl">
<form ng-submit="cardService()">
<input type="submit" value="Submit">
</form>
<p ng-model="card">{{card}}</p>
</div>
</body>
有什么想法吗?提前谢谢你。