【发布时间】:2014-09-07 20:40:54
【问题描述】:
我想知道如何在 $http POST 成功后清除联系人对象?代码在成功回调中的 this.contact = {}; 处出错。
angular.module('kbtApp')
.controller('ContactFormCtrl', function ($scope, $http, toaster) {
var that = this;
this.status = false;
this.contact = {
'fullname': 'Jim Rainaldi',
'email': 'jtrainali@gmail.com',
'organization': 'Jamesrainaldi.com',
'position': 'Web Guy',
'message': 'This is just a test.'
};
this.contact.isAjax = true;
this.sendEmail = function(){
var status = null;
var statuss = $http({
url: "/scripts/php/sendEmail.php",
method: "POST",
data: this.contact
}).success(function(data, status, headers, config) {
this.contact = {};
toaster.pop('success', "Success", 'Your message has been sent.', 7500, 'trustedHtml');
}).error(function(data, status, headers, config) {
//$scope.status = status;
toaster.pop('error', "Error", 'Email failed to send.', 7500, 'trustedHtml');
});
};
});
【问题讨论】:
-
将
this.contact更改为that.contact。 -
为什么不直接使用
$scope? -
当我在成功回调中设置断点时,我在开发工具中输入了 $scope,它返回 undefined。
标签: angularjs forms http reset