在 Angularjs 中提交后重置表单 [英] Resetting form after submit in Angularjs

查看:38
本文介绍了在 Angularjs 中提交后重置表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,可以在单击按钮时进行更新.

Hi I have a form which does update on button click.

 $scope.action = "Update";
  var id = $routeParams.editId;
  scope.item = updateRecord.get({ id: id });

更新项目后,它不会删除表单字段中输入的信息.我想知道 angularjs 中有什么可用在 udpating 之后添加到上面的代码中,以便它也清除形成.谢谢

Once the item is updated it doesn't remove the entered information in the form fields. I was wondering what is available in angularjs to add in the above code after udpating so that it also clears to form. Thanks

推荐答案

您可以通过 $scope.formName.$setPristine(); 重置表单,但如果您绑定的是模型对象对于您的输入,您也需要注意清除它们,即:

You can reset a form by, $scope.formName.$setPristine(); but if you're binding a model object to your inputs, you need to take care of clearing those too, ie:

$scope.currentRecord={};

编辑

ToodoN-Mike 指出,不要忘记设置

As ToodoN-Mike pointed out, don't forget to set

$scope.formName.$setUntouched()

$touched 标志是在 angular 1.3 中引入的.

The $touched flag was introduced in angular 1.3.

这篇关于在 Angularjs 中提交后重置表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆