J. *_*son 36 javascript angularjs angularjs-directive
嗨,我有一个表单,按钮点击更新.
$scope.action = "Update";
var id = $routeParams.editId;
scope.item = updateRecord.get({ id: id });
Run Code Online (Sandbox Code Playgroud)
项目更新后,它不会删除表单字段中输入的信息.我想知道在udpating之后在上面的代码中添加的angularjs中有什么可用,以便它也可以清除形式.谢谢
Moh*_*and 67
您可以通过重置表单,$scope.formName.$setPristine();但如果您将模型对象绑定到输入,则还需要注意清除它们,即:
$scope.currentRecord={};
编辑
正如ToodoN-Mike指出的那样,不要忘了设置
$scope.formName.$setUntouched()
该$touched标志是在角1.3引入.
Sam*_*l R 46
在提交函数的主体底部运行以下代码.
// Reset the form model.
vm.project = {};
// Set back to pristine.
vm.form.$setPristine();
// Since Angular 1.3, set back to untouched state.
vm.form.$setUntouched();
Run Code Online (Sandbox Code Playgroud)
"vm.form"是我的表格名称.
有关更多信息,请查看此文档页面:https: //docs.angularjs.org/api/ng/type/form.FormController
这对我有用.
viewModel.data = {};
$scope.formName.$setUntouched();
$scope.formName.$setPristine();
Run Code Online (Sandbox Code Playgroud)