本文介绍了在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 });

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

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 ()

在角1.3中引入了 $ touch 标志。

The $touched flag was introduced in angular 1.3.

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

08-18 21:13