我是 AngularJS 的新手,正在尝试做一个项目。我有一个完美运行的表格。然而,我应该做的只有一件事。添加客户后,我需要清除表单。因为,当用户想要添加第二个客户时,用户会看到之前输入的值。
$scope.add = function () {
$scope.loading = true;
$http.post('/api/Customer/', this.newcustomer).success(function (data) {
alert("Added Successfully!!");
$scope.addMode = false;
$scope.customers.push(data);
$scope.loading = false;
}).error(function (data) {
$scope.error = "An Error has occured while Adding Customer! " + data;
$scope.loading = false;
});
};
最佳答案
试试这个:
$scope.add = function () {
$scope.loading = true;
$http.post('/api/Customer/', this.newcustomer).success(function (data) {
alert("Added Successfully!!");
$scope.addMode = false;
$scope.customers.push(data);
$scope.loading = false;
this.newcustomer = {};
}).error(function (data) {
$scope.error = "An Error has occured while Adding Customer! " + data;
$scope.loading = false;
});
};
关于javascript - 如何在 AngularJS 中提交后重置表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37591314/