且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Angularjs中提交后重置表单

更新时间:2022-12-07 08:38:26

您可以通过 $ 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.