这是我与Angluar.js的第一个项目,我试图发布一个对象(personne),但它没有用。我的代码有问题吗?
myapp.controller('personCtrl', function ($scope, $http) {
$scope.connexion = function(personne) {
$http.post("http://localhost:8080/app/personne/testpost",$scope.personne)
.success(function(data, status) {
$scope.status = status;
$scope.data = data;
})
.error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
console.log('ca fonctionne');
});
答案 0 :(得分:0)
尝试这个。
$scope.connexion = function(personne) {
$http.post("http://localhost:8080/app/personne/testpost",{personne : $scope.personne}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
console.log('ca fonctionne');
};
答案 1 :(得分:0)
您在帖子请求中传递$scope
作为参数,但您需要将参数作为对象变量传递:
myapp.controller('personCtrl', function ($scope, $http) {
$scope.connexion = function(personne) {
$http.post("http://localhost:8080/app/personne/testpost",{persone: $scope.personne})
.success(function(data, status) {
$scope.status = status;
$scope.data = data;
})
.error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
console.log('ca fonctionne');
});
检查$http的角度文档。