我正在尝试创建一个angularjs联系表单。下面是我到目前为止创建的链接。 Click Here我用写的代码填满了我在写轨道上
var app = angular.module("myApp", []);
app.controller("contactCtrl", function ($scope) {
$scope.success = false;
$scope.error = false;
$scope.send = function () {
var htmlBody ='<div>Name: ' + $scope.user.name + '</div>' +
'<div>Email: ' + $scope.user.email + '</div>' +
'<div>Message: ' + $scope.user.body + '</div>' +
'<div>Date: ' + (new Date()).toString() + '</div>';
$http({
url: 'https://api.postmarkapp.com/email',
method: 'POST',
data: {
'From': '[email protected]',
'To': '[email protected]',
'HtmlBody': htmlBody,
'Subject': 'New Contact Form Submission'
},
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Postmark-Server-Token': '8569dcd45-6a1a-4e7b-ae75-ea37629de4'
}
}).
success(function (data) {
$scope.success = true;
$scope.user = {};
}).
error(function (data) {
$scope.error = true;
});
}
});
但是我收到两个错误
并且
{"error": "Please use POST request"}
有谁知道我能解决这个问题,我已经浪费了太多时间试图解决这个问题?
最佳答案
您不声明$http
。它应该是:
app.controller("contactCtrl", ['$scope','$http',function ($scope,$http){
// your code
}]);