javascript - 如何在 AngularJS 中提交后重置表单

标签 javascript jquery angularjs

我是 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/

相关文章:

javascript - 根据条件渲染 JSX 元素

javascript - 更改当前链接的 <li> 类

javascript - typedoc/jsdoc 文档通用参数(回调参数)

javascript - 当滚动到顶部而不是底部时,Ajax 起作用

javascript - 从我的 javascript 代码更改 div 样式

javascript - 如果满足条件,如何禁用 Angular Controller 中的按钮?

javascript - ng-repeat 不适用于数组

vim - 如何使用 Vim 和 Syntastic 忽略 Angular 指令 lint 错误

javascript - 渲染时 TextInput 闪烁/断断续续的行为

javascript - ajax 请求正在等待并行请求